QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401971 | #984. Happiness | grass8cow | WA | 2ms | 14304kb | C++17 | 2.0kb | 2024-04-29 17:47:44 | 2024-04-29 17:47:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,G=3,GI=(mod+1)/3;
int qpow(int a,int b){
int c=1;
for(;b;b>>=1){
if(b&1)c=1ll*a*c%mod;
a=1ll*a*a%mod;
}
return c;
}
int lb[1<<20],L,wi[1<<20][2];
void init(int n){
L=1;while(L<=n)L<<=1;
for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(int *a,int fl){
for(int i=0;i<L;i++)if(i<lb[i])swap(a[i],a[lb[i]]);
for(int o=1;o<L;o<<=1){
for(int i=0;i<L;i+=(o<<1))for(int j=0;j<o;j++){
int x=a[i+j],y=1ll*wi[j+o][fl]*a[i+j+o]%mod;
a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
}
}
if(!fl){
int I=qpow(L,mod-2);
for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod;
}
}
int se[201000],n,m,a[200100],p[201000],q[201000];
const int B=1000;
bool isi[200100];
int f[201000],z[201000];
int F[1<<20],Q[1<<20];
void build(){
for(int i=0;i<L;i++)F[i]=0;
//n-1-i i+j
for(int i=0;i<n;i++)F[n-1-q[i]]++;
NTT(F,1);for(int i=0;i<L;i++)F[i]=1ll*F[i]*Q[i]%mod;NTT(F,0);
for(int i=0;i<n;i++)f[i]=F[n-1+i];
}
int main(){
scanf("%d%d",&n,&m);init(n*4);
for(int o=1;o<L;o<<=1){
int p1=1,p2=1;
int o1=qpow(G,(mod-1)/(o<<1)),o2=qpow(GI,(mod-1)/(o<<1));
for(int j=0;j<o;j++){
wi[o+j][0]=p1,wi[o+j][1]=p2;
p1=1ll*p1*o2%mod,p2=1ll*p2*o1%mod;
}
}
if(n&1){for(int i=0;i<=m;i++)puts("0");return 0;}
for(int i=0;i<n;i++)scanf("%d",&se[i]),se[i+n]=se[i];
for(int i=1;i<n*2;i++)(se[i]+=se[i-1])%=mod;
for(int i=0;i<n;i++)a[i]=(se[i+n-n/4-1]-se[i+n/4])%mod;
for(int i=0;i<n;i++)p[i]=q[i]=i;
for(int i=0;i<n*2;i++)Q[i]=a[i%n];NTT(Q,1);
build();printf("%d\n",f[0]);
int dt=0;
vector<int>xz;
for(int i=1,oo,x,z;i<=m;i++){
scanf("%d",&oo);
if(oo==1){scanf("%d",&z);(dt+=z)%=n;}
else{
scanf("%d%d",&x,&z);(x+=n-dt)%=n;
(p[x]+=n-z)%=n;
if(!isi[x])isi[x]=1,xz.push_back(x);
}
int ans=f[dt];
for(int o:xz)(ans-=a[(q[o]+dt)%n])%=mod,(ans+=a[(p[o]+dt)%n])%=mod;
printf("%d\n",(ans+mod)%mod);
if(xz.size()>=B){for(int j=0;j<n;j++)q[j]=p[j];for(int o:xz)isi[o]=0;xz.clear();build();}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 14304kb
input:
6 3 1 2 4 8 16 32 2 1 4 1 5 2 4 2
output:
189 168 210 252
result:
ok 4 number(s): "189 168 210 252"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9856kb
input:
291 297 690864 66051 879316 361679 613199 616 951868 674311 509731 765530 914257 643036 149469 265479 385645 752029 360309 48606 545052 618893 70334 418974 673141 754792 299130 398298 719505 772883 898465 697947 205006 95537 798625 696927 962164 140276 704224 146457 73196 100864 371302 485115 950286...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 298 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 9812kb
input:
295 295 552765 106849 337718 329913 575893 164618 897059 355495 919669 763217 652119 598602 375615 550063 362338 802065 404469 248822 475588 743741 236314 886569 896687 949368 736118 824720 290749 488403 70211 243198 671570 94895 649763 349076 476023 628472 417057 350655 342355 826342 147267 922532 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 296 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 14052kb
input:
296 292 197804 718425 56634 403100 978753 617316 121593 944167 884895 801844 613148 623615 822920 116431 372795 179915 790109 774901 961724 265875 718476 818274 593528 45207 199271 233902 751601 242247 11775 88033 912182 946726 998679 382162 791540 990712 283984 188914 36965 121390 716244 896446 236...
output:
712685820 712685820 712685820 712685820 712685820 717318054 716983869 717589993 710256209 706016424 707153891 701271087 724635284 724417845 719673709 704630730 712569827 708723732 703114919 697699010 704624679 702212682 721430608 700393096 702244685 703289901 721707329 727986071 691394429 721590721 ...
result:
ok 293 numbers
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 14020kb
input:
294 291 503603 1295 528959 874005 16784 356063 407396 710552 364457 854105 81255 277227 337622 924237 786842 937442 324199 347508 759112 474964 795014 41077 989187 995407 337551 790107 640382 634943 493635 300299 850365 259818 324049 363697 636774 727713 680955 275129 475482 233431 36465 715331 5493...
output:
-755033289 243211064 243211064 241304462 246487749 244149180 242849351 243729937 242981876 240473501 241289144 239589122 242722412 243440252 240166011 244646621 239804677 244016243 246138296 246359596 244043738 245210022 244984337 243219614 242919477 249046022 239542717 237287596 243926344 240551676...
result:
wrong answer 1st numbers differ - expected: '243211064', found: '-755033289'