首页 > 其他 > 详细

I - Interesting Permutation Gym - 102394I

时间:2020-10-02 13:30:11      阅读:104      评论:0      收藏:0      [点我收藏+]

I - Interesting Permutation Gym - 102394I

Gym - 102394I 
如果h[i]==h[i-1],那么它只能选择最大值和最小值直接的位置,假设为tot
如果h[i]>h[i-1],那么当前位置为最大值或者最小值,ans*=2,差值也变大了,tot+=h[i]-h[i-1]-1;

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;i<=b;++i)
//2019.11.9
//by war
using namespace std;
long long T,n,ans,tot,Mod=1e9+7;
long long a[N];
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<0||c>9){if(c==-)y=-1;c=getchar();}
    while(c<=9&&c>=0){ x=(x<<1)+(x<<3)+c-0;c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){p(-);x=-x;}
    if(x>9)o(x/10);
    p(x%10+0);
}

signed main(){
    in(T);
    while(T--){
        in(n);
        ans=1;tot=0;
        For(i,1,n){
            in(a[i]);
            if(a[i]>=n) ans=0;
        }
        if(a[1]!=0) ans=0;
        For(i,2,n){

            if(a[i]==a[i-1]){
                ans*=tot--;
                ans%=Mod;
            }
            else if(a[i]>a[i-1]) ans<<=1,tot+=a[i]-a[i-1]-1,ans%=Mod;
            else {
                ans=0;break;
            }
        }
        o(ans);p(\n);
    }
    return 0;
}

 

I - Interesting Permutation Gym - 102394I

原文:https://www.cnblogs.com/war1111/p/13760467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!