QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64299#1443. Potato Shufflegyh20#WA 3ms3692kbC++141.5kb2022-11-24 16:02:392022-11-24 16:02:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 16:02:40]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3692kb
  • [2022-11-24 16:02:39]
  • 提交

answer

#include<bits/stdc++.h>
#define re register
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;
}
int 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(o-lst-(ask(o)-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("%d",ans);
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3488kb

input:

3 7
5 2 4

output:

3

result:

ok "3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

5 4
1 2 3 2 1

output:

10

result:

ok "10"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

6 4
9 10 1 9 8 9

output:

1

result:

ok "1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3536kb

input:

8 0
4 9 2 9 2 3 9 10

output:

1

result:

ok "1"

Test #5:

score: 0
Accepted
time: 2ms
memory: 3456kb

input:

5 3
9 8 1 9 8

output:

1

result:

ok "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

6 12
4 7 2 9 1 9

output:

60

result:

ok "60"

Test #7:

score: 0
Accepted
time: 3ms
memory: 3576kb

input:

10 18
9 6 3 9 5 3 9 9 5 1

output:

37800

result:

ok "37800"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

1 13
5

output:

1

result:

ok "1"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3392kb

input:

4 7
10 4 4 8

output:

1

result:

ok "1"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

2 4
3 3

output:

1

result:

ok "1"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3400kb

input:

3 12
8 1 6

output:

3

result:

ok "3"

Test #12:

score: 0
Accepted
time: 2ms
memory: 3436kb

input:

9 3
3 10 5 8 9 1 3 1 9

output:

1

result:

ok "1"

Test #13:

score: 0
Accepted
time: 3ms
memory: 3508kb

input:

10 19
8 9 6 8 3 5 8 8 8 2

output:

30240

result:

ok "30240"

Test #14:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

3 8
3 8 7

output:

1

result:

ok "1"

Test #15:

score: 0
Accepted
time: 2ms
memory: 3500kb

input:

5 6
8 7 6 8 3

output:

1

result:

ok "1"

Test #16:

score: 0
Accepted
time: 2ms
memory: 3508kb

input:

10 4
4 6 7 7 7 5 10 8 9 5

output:

1

result:

ok "1"

Test #17:

score: 0
Accepted
time: 2ms
memory: 3392kb

input:

3 5
9 5 8

output:

1

result:

ok "1"

Test #18:

score: 0
Accepted
time: 3ms
memory: 3632kb

input:

1 15
4

output:

1

result:

ok "1"

Test #19:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

4 0
9 2 8 9

output:

1

result:

ok "1"

Test #20:

score: 0
Accepted
time: 2ms
memory: 3460kb

input:

7 10
4 1 9 9 7 8 6

output:

7

result:

ok "7"

Test #21:

score: 0
Accepted
time: 2ms
memory: 3504kb

input:

9 15
9 10 10 9 1 2 2 9 3

output:

1512

result:

ok "1512"

Test #22:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

2 12
4 9

output:

1

result:

ok "1"

Test #23:

score: 0
Accepted
time: 3ms
memory: 3692kb

input:

941 1050595461
97199151 967582202 627391061 648812583 382698254 725831431 99920429 942104929 638728093 697787100 277585567 423990676 376336278 986391434 449561958 800545732 3456798 386231691 307296784 129242596 740319256 218489131 899192544 344153713 971619078 363368462 206242305 149813823 430534965...

output:

731201602

result:

ok "731201602"

Test #24:

score: -100
Wrong Answer
time: 3ms
memory: 3628kb

input:

931 1802136692
972656407 966750261 14838713 725079303 96491328 170902145 865911285 121473856 881400060 115397807 343248192 713973122 693395876 845120872 810689262 697741053 598095593 117050186 62294356 887558804 107838689 348014209 207407232 962013618 291145455 44153613 619738233 106508008 266410860...

output:

79768607

result:

wrong answer 1st words differ - expected: '910622578', found: '79768607'