QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633225#9451. Expected Waiting Timeucup-team3161#TL 871ms10316kbC++201014b2024-10-12 14:50:222024-10-12 14:50:22

Judging History

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

  • [2024-10-12 14:50:22]
  • 评测
  • 测评结果:TL
  • 用时:871ms
  • 内存:10316kb
  • [2024-10-12 14:50:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
int T,n,MOD,A,B,ans,a[N],b[N],s[N],fc[N],invfc[N];
int qpow(int x,int y)
{
    int res=1;
    for(;y;y/=2,x=1ll*x*x%MOD) if(y&1)
        res=1ll*res*x%MOD;return res;
}
void init(int n)
{
    fc[0]=1;for(int i=1;i<=n;++i) fc[i]=fc[i-1]*i%MOD;
    invfc[n]=qpow(fc[n],MOD-2);
    for(int i=n;i;--i) invfc[i-1]=invfc[i]*i%MOD;
}
int bn(int x,int y) {return x<y || y<0?0:fc[x]*invfc[y]%MOD*invfc[x-y]%MOD;}
int cat(int x) {return x?(bn(x*2,x)-bn(x*2,x-1)+MOD)%MOD:1;}
void slv()
{
    scanf("%lld %lld %lld %lld %lld",&n,&MOD,&b[0],&A,&B);ans=0;init(n*2);
    for(int i=1;i<=n*2;++i) b[i]=(A*b[i-1]+B)%MOD,a[i]=(a[i-1]+b[i]+1)%MOD;
    for(int i=1;i<=n*2;++i) s[i]=(s[i-1]+a[n*2-i+1]-a[i]+MOD)%MOD;
    for(int i=0;i<n;++i) ans=(ans+cat(i)*cat(n-i-1)%MOD*s[i*2+1])%MOD;
    ans=1ll*ans*qpow(cat(n),MOD-2)%MOD;printf("%d\n",ans);
}
signed main()
{
    scanf("%d",&T);
    while(T--) slv();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8016kb

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: 871ms
memory: 10316kb

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
Time Limit Exceeded

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:


result: