QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631643#9451. Expected Waiting Timeucup-team896#WA 520ms35200kbC++141.0kb2024-10-12 09:25:112024-10-12 09:25:11

Judging History

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

  • [2024-10-12 09:25:11]
  • 评测
  • 测评结果:WA
  • 用时:520ms
  • 内存:35200kb
  • [2024-10-12 09:25:11]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=2e6+5;
int n,Mod,A,B;
int a[N],b[N],H[N],F[N],inv[N];
inline int qpow(int x,int y,int z=1){
	for(;y;(y>>=1)&&(x=(LL)x*x%Mod))if(y&1)z=(LL)z*x%Mod;return z;
}
inline void MAIN(){
	cin>>n>>Mod>>b[0]>>A>>B;
	for(int i=1;i<=n+n;++i)
		b[i]=(1ll*b[i-1]*A+B)%Mod,a[i]=(a[i-1]+b[i]+1)%Mod;
	inv[1]=1;
	for(int i=2;i<=n+1;++i)
		inv[i]=(Mod-Mod/i*(LL)inv[Mod%i]%Mod);
	H[0]=1;
	for(int i=1;i<=n;++i)
		H[i]=(4*i-2ll)*H[i-1]%Mod*inv[i+1]%Mod;
	for(int i=1;i<=n;++i)
		F[i]=(F[i-1]+1ll*H[n-i]*H[i-1])%Mod;
	int ans=0;
	for(int i=1;i<=n+n;++i)
		ans=(ans+(H[n]-F[(n+n-i+1)/2]*2ll)*a[i])%Mod;
	ans=qpow(H[n],Mod-2,ans);
	cout<<(ans<0?ans+Mod:ans)<<'\n';
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
	int t=1;cin>>t;while(t--)MAIN();
    return 0;
}
/*
5
1 1000000007 0 1 0
2 1000000007 0 1 1
2 7 5 2 3
3 31 15 6 24
20 1000000007 0 1 0
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7772kb

input:

5
1 1000000007 0 1 0
2 1000000007 0 1 1
2 7 5 2 3
3 31 15 6 24
20 1000000007 0 1 0

output:

1
12
1
21
879705565

result:

ok 5 number(s): "1 12 1 21 879705565"

Test #2:

score: 0
Accepted
time: 494ms
memory: 7884kb

input:

4400
3954 1000000007 0 1 0
1306 1000000007 0 1 0
3774 1000000007 0 1 0
3345 1000000007 0 1 0
891 1000000007 0 1 0
2462 1000000007 0 1 0
237 1000000007 0 1 0
26 1000000007 0 1 0
2510 1000000007 0 1 0
637 1000000007 0 1 0
3250 1000000007 0 1 0
3447 1000000007 0 1 0
1222 1000000007 0 1 0
133 1000000007...

output:

440618338
378292891
979368645
915766295
343598158
80867595
161627927
517387931
396936703
42785642
945720545
764273281
186237656
635777911
164064906
548455037
991964184
468137124
561243246
118562285
856945294
642467240
23673926
808943705
897417615
462422554
656411244
204288121
997894281
244685651
762...

result:

ok 4400 numbers

Test #3:

score: -100
Wrong Answer
time: 520ms
memory: 35200kb

input:

1019
338 1863833207 1820742817 1507924477 1822273457
770 1386304741 1088481071 1216187083 170973217
597 1604266739 620750027 196415899 456280997
105 1008587891 184044403 24836083 926135599
357 1165127407 440925347 1103369747 912263123
82 1639766993 263045351 631010551 1412721139
928 1715915153 25383...

output:

116158230
707327521
1548853053
827110887
667053406
1320168783
22460269
1402459563
876954087
855042464
1009499206
793070751
1255321747
239865882
270818359
1306207601
945930977
994267280
175524931
685678160
643679528
708997341
867380212
103253987
558752169
1050819260
1011880034
844160548
686316621
106...

result:

wrong answer 1st numbers differ - expected: '1532578211', found: '116158230'