QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203386 | #3840. Pass the Ball! | ushg8877# | WA | 6ms | 8156kb | C++20 | 2.1kb | 2023-10-06 17:05:56 | 2023-10-06 17:05:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LL __int128
#define MP make_pair
#define poly vector<long long>
mt19937 rnd(time(0));
const ll MOD1=998244353;
const ll MOD2=1004535809;
const LL v1=668514958533372747ll,v2=334257240187163831ll;
const int MAXN=1e6+5;
int bfly[MAXN];
template<const int MOD> void NTT(poly &F,int l,int typ){
auto ksm=[&](ll a,int b){ll res=1;while(b){if(b&1)res=res*a%MOD;a=a*a%MOD,b>>=1;}return res;};
for(int i=1;i<(1<<l);i++) bfly[i]=(bfly[i>>1]>>1)|((i&1)<<l-1);
for(int i=0;i<(1<<l);i++) if(bfly[i]<i) swap(F[i],F[bfly[i]]);
for(int i=1;i<=l;i++){
ll step=ksm(3,(MOD-1)+((MOD-1)>>i)*typ);
for(int j=0;j<(1<<l);j+=(1<<i)){
ll cur=1;
for(int k=j;k<(j|(1<<i-1));k++){
ll u=F[k],v=F[k|(1<<i-1)]*cur%MOD;
F[k]=(u+v)%MOD;F[k|(1<<i-1)]=(u-v+MOD)%MOD;
cur=cur*step%MOD;
}
}
}
if(typ==-1){
ll p=ksm(1<<l,MOD-2);
for(int i=0;i<(1<<l);i++) F[i]=F[i]*p%MOD;
}
return;
};
template<const int MOD> poly prod(poly F,poly G){
int n=F.size()+G.size()-1;
int k=ceil(log2(n+1));
F.resize(1<<k);G.resize(1<<k);
NTT<MOD>(F,k,1);NTT<MOD>(G,k,1);
for(int i=0;i<(1<<k);i++) F[i]=F[i]*G[i]%MOD;
NTT<MOD>(F,k,-1);
F.resize(n);
return F;
}
poly operator *(poly F,poly G){
poly H1=prod<MOD1>(F,G),H2=prod<MOD2>(F,G);
poly H=H1;
for(int i=0;i<H1.size();i++)
H[i]=(H1[i]*v2+H2[i]*v1)%(MOD1*MOD2);
return H;
}
int n,q;
int p[MAXN];bool vis[MAXN];
poly cyc,rcyc;
map<int,poly> mp;
void dfs(int x){
if(vis[x]) return;
vis[x]=true;
cyc.push_back(x);
dfs(p[x]);
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>q;
for(int i=1;i<=n;i++) cin>>p[i];
for(int i=1;i<=n;i++) if(!vis[i]){
cyc.clear();
dfs(i);
rcyc=cyc;
int k=cyc.size();
reverse(rcyc.begin(),rcyc.end());
for(int i=0;i<k;i++) rcyc.push_back(rcyc[i]);
cyc=cyc*rcyc;
if(!mp.count(k)){
for(int j=0;j<k;j++) mp[k].push_back(cyc[j+k-1]);
}else{
for(int j=0;j<k;j++) mp[k][j+k-1]+=cyc[j+k-1];
}
}
while(q--){
int x;cin>>x;ll ans=0;
for(auto &i:mp) ans+=i.second[x%i.first];
cout<<ans<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8036kb
input:
4 4 2 4 1 3 1 2 3 4
output:
25 20 25 30
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 5988kb
input:
3 6 2 3 1 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 6128kb
input:
3 6 3 1 2 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #4:
score: 0
Accepted
time: 3ms
memory: 6096kb
input:
1000 10000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
333334000 332835500 332338000 331841500 331346000 330851500 330358000 329865500 329374000 328883500 328394000 327905500 327418000 326931500 326446000 325961500 325478000 324995500 324514000 324033500 323554000 323075500 322598000 322121500 321646000 321171500 320698000 320225500 319754000 319283500 ...
result:
ok 10000 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 6168kb
input:
1000 10000 187 493 316 665 124 40 448 649 657 65 438 730 816 107 789 286 309 469 169 216 488 52 212 111 541 83 990 48 282 867 36 220 676 241 959 372 322 244 481 708 595 957 215 223 120 658 291 176 229 158 431 492 221 986 889 861 606 518 106 349 410 765 745 812 563 998 150 392 358 328 747 793 587 507...
output:
250347169 248662078 245260552 253150328 247096579 249698948 249942589 251180693 248589849 253775352 248472247 248369272 249001282 249611561 251718722 248202949 252492155 251442262 255269934 247070745 248898892 250071493 249262069 247714054 248954719 251676093 251650611 249152315 248608212 249678723 ...
result:
ok 10000 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 6064kb
input:
1000 10000 301 793 604 129 545 524 625 540 271 616 710 629 682 190 152 287 40 5 921 699 730 427 833 680 514 782 641 754 15 218 725 862 238 468 917 368 850 35 243 339 688 460 597 979 398 748 552 25 189 68 115 76 888 844 890 102 835 581 266 342 571 749 574 156 717 538 440 764 601 831 130 39 136 842 78...
output:
250889096 249771741 249454079 255348475 249559048 257117687 248782164 250050189 254433188 254774148 251601723 250597849 251570596 249861162 256368189 253409601 254026050 249568513 248807065 253946543 254531155 252620668 255570774 257943265 252823304 255566622 252678751 254417015 252540528 256854774 ...
result:
ok 10000 lines
Test #7:
score: 0
Accepted
time: 6ms
memory: 6032kb
input:
1000 10000 163 149 53 93 995 744 452 73 683 474 213 597 903 190 842 487 894 256 339 588 902 930 870 632 992 561 455 248 961 788 188 436 421 887 847 361 311 192 706 636 352 233 987 376 323 32 120 565 546 730 191 587 404 22 817 906 585 420 621 167 132 816 431 200 952 180 402 838 794 284 349 94 427 482...
output:
250865862 251948566 251553098 253385993 250129972 254017302 254493541 251442447 247937015 250833800 249523549 249193386 252059812 249370594 254109165 249397918 247138568 248934855 249807415 251196617 250357758 249395769 248148350 247009170 252163335 249850249 250639740 251827755 247795165 253868762 ...
result:
ok 10000 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 6056kb
input:
1000 10000 384 881 331 471 166 902 45 90 353 415 895 74 693 69 887 878 807 436 538 328 892 750 294 891 238 527 406 464 23 259 200 731 336 62 30 157 457 243 956 485 670 37 405 16 14 162 484 875 64 38 305 177 391 882 440 649 296 702 990 953 468 109 915 316 622 81 863 286 412 584 659 271 282 984 490 97...
output:
251829371 249579880 249800743 251369774 250567175 248916841 252235114 251856809 249117279 247474406 250612288 247256785 251394491 250004784 252462213 249291071 251938054 251833233 254868301 251496842 242701038 251189092 250051802 248910394 249438626 245833186 250955694 251605815 251188358 253696421 ...
result:
ok 10000 lines
Test #9:
score: -100
Wrong Answer
time: 3ms
memory: 8156kb
input:
1000 10000 791 811 116 51 267 840 647 573 765 859 154 984 879 576 938 308 808 301 287 158 43 453 284 243 945 585 156 648 447 331 930 296 657 820 991 457 969 237 644 784 514 685 487 506 353 854 336 7 111 324 593 4 234 548 680 923 501 186 201 918 821 968 549 236 171 173 553 476 882 569 74 841 910 689 ...
output:
229935525 220408181 223222292 221552470 222768977 217811208 217574957 222070784 217651751 222608990 222241616 222583487 218496558 220458487 220190838 224107632 219228543 223849786 221054582 226305429 218099798 232882819 221106414 220135703 215328026 226388686 221869450 219544950 219841179 222861944 ...
result:
wrong answer 1st lines differ - expected: '260869097', found: '229935525'