QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189118 | #3840. Pass the Ball! | OccDreamer | WA | 59ms | 18112kb | C++14 | 3.8kb | 2023-09-26 21:21:53 | 2023-09-26 21:21:53 |
Judging History
answer
//code by Emissary
#include<bits/stdc++.h>
#define fi first
#define se second
#define vc vector
#define db double
#define ll long long
#define mk make_pair
#define pb push_back
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << " -_- " << endl
#define debug cerr << " ------------------- " << endl
#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)
#define NO puts("No")
#define YES puts("Yes")
#define int long long
using namespace std;
namespace IO{
inline int read(){
int X=0, W=0; char ch=getchar();
while(!isdigit(ch)) W|=ch=='-', ch=getchar();
while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
return W?-X:X;
}
inline void write(ll x){
if(x<0) x=-x, putchar('-');
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline void sprint(ll x){write(x), putchar(32);}
inline void eprint(ll x){write(x), putchar(10);}
}using namespace IO;
const int MAXN = (1 << 21) + 23333;
const long double P = acos(-1.0);
int cnt;
int q, nxt[MAXN], ri[MAXN];
vc<int> node;
ll v[MAXN];
vector<vector<ll> > buc;
bool vis[MAXN];
inline void dfs(int x){
node.pb(x); vis[x]=1;
if(!vis[nxt[x]]) dfs(nxt[x]);
}
struct complexx{
long double x, y;
complexx friend operator + (const complexx &x, const complexx &y){return complexx{x.x+y.x,x.y+y.y};}
complexx friend operator - (const complexx &x, const complexx &y){return complexx{x.x-y.x,x.y-y.y};}
complexx friend operator * (const complexx &x, const complexx &y){return complexx{x.x*y.x-x.y*y.y,x.y*y.x+x.x*y.y};}
}a[MAXN], b[MAXN];
int n, m;
int limit;
int dp[MAXN];
inline int lowbit(int x){return x & -x;}
inline void getdp(int limit){for(int i=1;i<limit;++i) dp[i]=dp[i-lowbit(i)]+limit/(2*lowbit(i));}
inline void FFTA(int limit, int tp){
complexx W, Wn, A, B;
for(int i=0;i<limit;++i) if(i<dp[i]) swap(a[i],a[dp[i]]);
for(int L=1;L<limit;L<<=1){
Wn=complexx{cos(P/((long db)L)),sin(P/((long db)L))};
if(tp==-1) Wn.y=-Wn.y;
for(int R=L<<1, pos=0;pos<limit;pos+=R){
W=complexx{1,0};
for(int k=0;k<L;++k, W=W*Wn){
A=a[pos+k], B=a[pos+k+L]*W;
a[pos+k]=A+B;
a[pos+k+L]=A-B;
}
}
}
return ;
}
inline void FFTB(int limit, int tp){
complexx W, Wn, A, B;
for(int i=0;i<limit;++i) if(i<dp[i]) swap(b[i],b[dp[i]]);
for(int L=1;L<limit;L<<=1){
Wn=complexx{cos(P/((long db)L)),sin(P/((long db)L))};
if(tp==-1) Wn.y=-Wn.y;
for(int R=L<<1, pos=0;pos<limit;pos+=R){
W=complexx{1,0};
for(int k=0;k<L;++k, W=W*Wn){
A=b[pos+k], B=b[pos+k+L]*W;
b[pos+k]=A+B;
b[pos+k+L]=A-B;
}
}
}
return ;
}
inline void FFT(int siz){
int limit=1;
while(limit<=siz*3+3) limit<<=1; getdp(limit);
for(int i=0;i<limit;++i) a[i]=b[i]=complexx{0,0};
for(int i=0;i<siz;++i) b[i]=complexx{node[i],0};
for(int i=0, j=siz-1;i<siz;++i, --j) a[i]=complexx{node[j],0};
for(int i=siz;i<siz<<1;++i) a[i]=complexx{a[i-siz].x,0};
FFTA(limit,1); FFTB(limit,1);
for(int i=0;i<limit;++i) a[i]=a[i]*b[i];
FFTA(limit,-1);
for(int i=0;i<limit;++i) v[i]=(ll)(a[i].x/((long db)limit)+0.99997);
for(int i=0, j=siz-1;i<siz;++i, --j) buc[siz][j]+=v[siz+i];
return ;
}
signed main(){
int x;
n=read(); q=read(); buc.resize(n+1);
for(int i=1;i<=n;++i) x=read(), nxt[i]=x;
for(int i=1;i<=n;++i){
if(!vis[i]){
node.clear();
dfs(i); int t=node.size();
if(buc[t].size()==0) buc[t].resize(t+2);
FFT(t); ri[++cnt]=t;
}
}
sort(ri+1,ri+1+cnt); cnt=unique(ri+1,ri+1+cnt)-ri-1;
while(q--){
int k=read(); ll ans=0;
for(int i=1;i<=cnt;++i) ans+=buc[ri[i]][k%ri[i]];
eprint(ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13692kb
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: 13716kb
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: 2ms
memory: 13852kb
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: 4ms
memory: 13720kb
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: 13768kb
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: 0ms
memory: 13716kb
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: 0ms
memory: 13764kb
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: 13724kb
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: 0
Accepted
time: 0ms
memory: 13756kb
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:
260869097 250249635 252485552 251312537 249827807 247891441 247306872 250706363 246507025 251504505 253441362 252531355 248389010 251206287 251647794 256299060 251419971 256041214 250785378 257137028 247372087 262923110 250837210 248771282 245058822 265251780 251710904 249728123 250029619 252510223 ...
result:
ok 10000 lines
Test #10:
score: 0
Accepted
time: 4ms
memory: 13712kb
input:
1000 10000 107 858 884 149 531 779 189 350 748 934 302 276 957 567 102 902 906 898 373 631 532 743 683 856 625 610 80 863 986 16 322 141 538 352 758 5 656 870 828 180 982 356 308 19 240 422 622 859 850 331 565 472 321 365 962 941 638 188 448 403 864 588 222 22 184 854 300 554 781 711 973 324 283 359...
output:
252498827 250467741 245004582 254567945 248723182 266747940 252248407 250985182 246296872 258740339 250929702 252439407 264653513 256570063 251140559 251878111 245187220 257848088 248480375 257243736 247751395 252036917 250285176 249672867 247804044 247486222 252436982 247016052 254469398 257746086 ...
result:
ok 10000 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 13844kb
input:
1000 10000 469 92 385 860 536 350 852 471 547 625 369 749 339 169 21 565 312 801 41 996 326 280 660 211 910 75 929 202 768 652 865 4 498 109 179 568 601 167 276 661 297 654 909 958 922 815 515 673 253 771 879 108 682 405 476 418 604 847 225 265 329 270 228 872 571 775 69 180 118 78 35 808 795 412 13...
output:
249086375 263201066 251739073 251359274 253144475 272709870 251828190 252458176 265505472 261406223 268442012 246572070 247852028 276578867 252522304 277213878 270316579 252964972 261401771 275240590 279151202 251157983 259726293 256059004 255499430 253949570 253723754 275131199 250198559 251473808 ...
result:
ok 10000 lines
Test #12:
score: 0
Accepted
time: 4ms
memory: 13704kb
input:
1000 10000 458 237 370 989 962 641 819 68 976 944 204 184 479 612 434 436 765 572 554 959 36 710 891 584 882 521 928 94 263 633 406 833 534 363 513 21 281 745 699 864 669 850 529 315 455 375 292 60 70 685 782 613 344 217 931 862 739 215 691 48 635 940 182 348 188 801 432 8 696 49 236 772 539 757 193...
output:
333833500 333833500 333833500 249545048 333833500 249545048 249545048 249545048 249545048 249545048 249545048 333833500 249545048 333833500 249545048 333833500 249545048 249545048 333833500 333833500 249545048 249545048 333833500 249545048 249545048 249545048 333833500 333833500 249545048 333833500 ...
result:
ok 10000 lines
Test #13:
score: 0
Accepted
time: 14ms
memory: 16172kb
input:
10000 100000 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 1...
output:
333333340000 333283355000 333233380000 333183415000 333133460000 333083515000 333033580000 332983655000 332933740000 332883835000 332833940000 332784055000 332734180000 332684315000 332634460000 332584615000 332534780000 332484955000 332435140000 332385335000 332335540000 332285755000 332235980000 3...
result:
ok 100000 lines
Test #14:
score: 0
Accepted
time: 19ms
memory: 15960kb
input:
10000 100000 4607 827 2035 8615 3621 5753 3932 7905 1928 4478 5212 6050 9017 7801 9811 9915 9016 8789 8088 1285 7024 2588 9126 5626 2342 820 9729 3840 1698 6592 9503 4539 1200 9586 5650 1792 1370 9214 8008 1578 2937 861 8952 630 5 1549 1691 3823 8220 436 9397 552 3935 9346 9368 3452 6402 4204 1080 9...
output:
249897347061 249896131590 249914750798 250458981867 249010978963 250037157372 248895507307 250697367512 251229099297 251001758448 249307655388 250326734894 249317989317 249618346287 249956029481 249472860797 249424124234 249474623368 249293835077 250221547890 250595811813 249278269199 249412896604 2...
result:
ok 100000 lines
Test #15:
score: 0
Accepted
time: 59ms
memory: 13912kb
input:
10000 100000 3060 5228 9664 4133 7280 6675 1186 4393 5115 3785 1706 4049 9609 8331 584 367 763 3324 3730 2940 7089 9493 6060 8108 148 9067 2686 9080 7945 1886 9097 832 8629 3031 7989 1566 2970 3587 9375 4996 9481 138 4990 6694 1907 590 6692 6447 6970 1429 7316 4663 58 6087 5417 2125 5713 177 6834 17...
output:
249379335677 250564028686 249911690942 248759909742 248942895751 250505472878 249995950694 249424346881 249384707925 250679254354 248794871167 251400405963 250598317733 251055417333 250564452666 249397413463 250591860942 247884917961 248830215526 248556895505 252555537555 250588052750 249442159148 2...
result:
ok 100000 lines
Test #16:
score: -100
Wrong Answer
time: 17ms
memory: 18112kb
input:
10000 100000 1865 8212 6189 8845 5317 6184 6105 8956 4399 7299 3095 9106 3066 8505 2222 3002 3734 1323 8155 7274 6647 5186 6612 9091 9395 3227 6012 5654 6383 2776 7960 4432 4723 9968 8804 5288 86 1785 4093 1346 7818 9246 2185 6951 7814 5103 551 6023 5780 570 5535 6643 9724 7526 7714 8406 4990 8875 2...
output:
249107703017 250929022770 248973455287 251215085728 250154830044 250021851268 248840792335 249317564185 249529439725 250051242908 249104026929 250644846835 250253578972 249451030934 250122048818 250546832164 250567786988 249322165564 249606784866 249266200556 250163660304 249101131437 249618662247 2...
result:
wrong answer 7th lines differ - expected: '248840792334', found: '248840792335'