QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64302 | #1443. Potato Shuffle | gyh20# | WA | 2ms | 3636kb | C++14 | 1.6kb | 2022-11-24 16:18:49 | 2022-11-24 16:18:50 |
Judging History
answer
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
re int t=0;re char v=getchar();
while(v<'0')v=getchar();
while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
return t;
}
const int M=1e9+7;
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
inline int Mod(re int x){return x>=M?x-M:x;}
inline int ksm(re int x,re int y){
re int s=1;
while(y){
if(y&1)s=1ll*s*x%M;
x=1ll*x*x%M,y>>=1;
}
return s;
}
int t,n,m,a[1000002],ans,A,B,R[1000002],stk[1000002],tp,T[1000002],k,c[1000002],fac[1000002],inv[1000002];
char s[1000002];
set<int>S,P;
map<int,vector<int> >V;
inline void Add(re int x,re int y){for(;x<=n;x+=x&(-x))c[x]+=y;}
inline int ask(re int x,re int s=0){for(;x;x^=x&(-x))s+=c[x];return s;}
inline int calc(re int x,re int y){
x-=1;
return 1ll*fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main(){
n=read(),m=read(),ans=1;
for(re int i=fac[0]=inv[0]=1;i<=n+1;++i)fac[i]=1ll*fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
for(re int i=1;i<=n;++i)a[i]=read(),S.insert(a[i]),V[a[i]].push_back(i);
for(auto z:S)T[++k]=z;int pos=k;
P.insert(0),P.insert(n+1);
for(re int i=1;i<=k&&T[i]+T[i]<=m;++i){
while(T[i]+T[pos]>m){
for(auto z:V[T[pos]])P.insert(z);
--pos;
}
int lst=0,num=0;
for(auto z:V[T[i]]){
int o=*--P.lower_bound(z);
if(o==lst)++num;
else ans=1ll*ans*calc(*P.upper_bound(lst)-lst-(ask(*P.upper_bound(lst))-ask(lst)),num)%M,num=1,lst=o;
}
int o=*P.upper_bound(lst);
ans=1ll*ans*calc(o-lst-(ask(o)-ask(lst)),num)%M;
for(auto z:V[T[i]])Add(z,1);
}
printf("%lld",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
3 7 5 2 4
output:
3
result:
ok "3"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3460kb
input:
5 4 1 2 3 2 1
output:
20
result:
wrong answer 1st words differ - expected: '10', found: '20'