QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#55904 | #3840. Pass the Ball! | Ctrl2333# | WA | 198ms | 81728kb | C++17 | 3.1kb | 2022-10-15 16:06:10 | 2022-10-15 16:06:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
const long double pi=acos(-1.0);
namespace IO{
inline int getint(){
char c;
while(!isdigit(c=gc()));int num=c^48;
while(isdigit(c=gc()))num=(num+(num<<2)<<1)+(c^48);
return num;
}
}
using namespace IO;
struct Comp{
long double x,y;
Comp(long double _x=0.0,long double _y=0.0){
x=_x,y=_y;
}
Comp operator -(const Comp &b)const{
return Comp(x-b.x,y-b.y);
}
Comp operator +(const Comp &b)const{
return Comp(x+b.x,y+b.y);
}
Comp operator *(const Comp &b)const{
return Comp(x*b.x-y*b.y,x*b.y+y*b.x);
}
};
const int maxn=3010000;
typedef vector<Comp > Poly;
int r[maxn];
inline void FFT(Poly &A,int len, int typ){
for(int i=0;i<len;i++)if(i<r[i])swap(A[i],A[r[i]]);
for(int h=2;h<=len;h<<=1){
Comp wn(cos(2.0*pi/h),sin(typ*2.0*pi/h));
for(int j=0;j<len;j+=h){
Comp w(1,0);
for(int k=j;k<j+(h>>1);k++){
Comp u=A[k], t=w*A[k+(h>>1)];
A[k]=u+t,A[k+(h>>1)]=u-t;
w=w*wn;
}
}
}
if(typ==-1)for(int i=0;i<len;i++)A[i].x/=(long double)len;
}
inline void init_rev(int len){
for(int i=0;i<len;i++)r[i]=r[i>>1]>>1|((i&1)*(len>>1));
}
inline Poly operator+(const Poly &a, const Poly &b){
Poly c=a;c.resize(max(a.size(),b.size()));
for(int i=0;i<b.size();i++)c[i]=c[i]+b[i];
return c;
}
Poly operator*(Poly a,Poly b){
int n=a.size(),m=b.size(),l=1;
while(l<n+m-1)l<<=1;
init_rev(l);
a.resize(l),FFT(a,l,1);
b.resize(l),FFT(b,l,1);
for(int i=0;i<l;i++)a[i]=a[i]*b[i];
FFT(a,l,-1);
a.resize(n+m-1);
return a;
}
int n,q;
int f[100005];
Poly poly[100005];
vector<int>ring;
int vis[100005];
int stk[100005],top;
inline void print(Poly &a){
for(int i=0;i<a.size();i++){
printf("%lf ",a[i].x);
}
printf("\n");
}
void dfs(int u){
vis[u]=1;
stk[++top]=u;
if(vis[f[u]]){
Poly p1,p2;
for(int k=0;k<2;k++){
for(int i=1;i<=top;i++){
Comp ne(stk[i],0);
p1.push_back(ne);
}
}
for(int i=top;i>=1;i--){
//cout<<"U:"<<u<<" node:"<<stk[i]<<endl;
Comp ne(stk[i],0);
p2.push_back(ne);
}
Poly res=p1*p2;
//print(res);
poly[top] = poly[top] + res;
}
else{
dfs(f[u]);
}
top--;
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
scanf("%d",&f[i]);
}
for(int i=1;i<=n;i++){
if(!vis[i])dfs(i);
}
for(int i=2;i<=100000;i++){
if(poly[i].size())ring.push_back(i);
//print(poly[i]);
}
for(int qq=1;qq<=q;qq++){
long long k;scanf("%lld",&k);
long long ans=0;
for(int i=0;i<ring.size();i++){
ans+=(long long)(poly[ring[i]][k%ring[i]+ring[i]-1].x+0.1);
}
printf("%lld\n",ans);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6116kb
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: 3ms
memory: 6388kb
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: 6784kb
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: 7ms
memory: 7012kb
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: 7ms
memory: 6468kb
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: 10ms
memory: 7164kb
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: 6688kb
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: 5ms
memory: 6536kb
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: 8ms
memory: 6984kb
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: 8ms
memory: 6460kb
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: 11ms
memory: 6344kb
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: 2ms
memory: 6272kb
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: 28ms
memory: 11984kb
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: 42ms
memory: 9960kb
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: 131ms
memory: 7276kb
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: 0
Accepted
time: 31ms
memory: 12092kb
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 248840792334 249317564185 249529439725 250051242908 249104026928 250644846835 250253578971 249451030933 250122048817 250546832164 250567786988 249322165564 249606784865 249266200556 250163660303 249101131436 249618662246 2...
result:
ok 100000 lines
Test #17:
score: 0
Accepted
time: 32ms
memory: 8604kb
input:
10000 100000 6756 1688 6229 8371 1121 6531 1327 3562 1768 8888 6604 6762 515 8098 9301 562 3335 1848 4949 2210 9602 8094 3482 7916 6682 9756 8314 9554 9352 9991 6879 6569 2139 667 5814 2389 6591 4948 7665 3237 3183 9256 3619 1680 8499 3297 2930 721 1685 8677 8295 1328 3836 8333 4957 232 5717 875 547...
output:
249413590668 250313669717 250120939437 251046713667 250338695308 249069427057 249030353190 250713504985 249728489343 250331020584 251118048063 248364056694 250104400530 249896454300 250223547797 250505288965 249857011499 249213206687 251308938646 250067941589 250568941268 251185223377 249006848082 2...
result:
ok 100000 lines
Test #18:
score: 0
Accepted
time: 31ms
memory: 7804kb
input:
10000 100000 6834 9774 8757 6224 7707 567 7008 3983 7254 524 6364 1477 3360 2086 1242 397 1866 8601 4243 842 8164 635 2512 5326 4113 9727 5567 7437 2174 4262 8285 9958 5737 9309 4735 4318 9519 8021 9092 1226 4344 4815 5133 1938 6561 5431 3675 8975 4847 6122 2615 9095 888 323 2061 9479 9150 1664 5442...
output:
249391457751 249144573525 249235798206 249801921233 250866407752 248156473123 251531256938 249672114201 250515294374 250158604394 250019094112 248157388395 258436907150 248759723271 248882610224 250259263845 249819631685 250426409008 250671783525 251038483637 249795464283 249738859699 250546320729 2...
result:
ok 100000 lines
Test #19:
score: 0
Accepted
time: 61ms
memory: 6672kb
input:
10000 100000 4369 1328 3935 2770 3588 597 1455 321 8882 4274 5618 6324 3471 3558 363 2260 5007 1182 8941 4808 1714 1633 1475 5647 4904 2573 9780 8030 8078 3597 9596 1094 3089 7354 1269 1199 5466 2688 461 2537 1966 8300 7448 6270 4780 3410 4631 9156 147 5799 1866 3970 1962 1756 2925 1991 2840 9134 85...
output:
251033524625 253231950867 252486951128 254721597125 250015952915 249953876719 254278282953 250906246099 249552099337 251985200841 251406244446 250380611061 248894069395 248652822754 249522730742 250454568288 250938727619 252355485102 248611902908 250081544502 250134712813 250635393346 248977789292 2...
result:
ok 100000 lines
Test #20:
score: 0
Accepted
time: 72ms
memory: 6684kb
input:
10000 100000 3026 1782 7464 1195 7717 6038 7803 706 9651 7326 6394 2105 4890 612 4484 3101 8048 2242 9406 9816 1080 3787 3325 9987 4473 3067 5801 6524 6669 4429 8628 7072 5133 7387 9026 5291 3730 5217 1602 7497 7067 3669 3534 7194 65 8569 774 8625 5330 7159 7954 2392 4980 6252 4652 3501 110 935 245 ...
output:
250602248329 249576983172 250656406457 249472500232 253038164808 249925949345 252969572313 252481279455 251912755337 249322258206 250976438434 249410519066 250432743063 249337775548 253502925344 249115644605 250407989563 252107917079 257659186636 250576213702 253112589725 250016704234 249269659220 2...
result:
ok 100000 lines
Test #21:
score: 0
Accepted
time: 47ms
memory: 6268kb
input:
10000 100000 7348 500 3092 7277 2466 1248 7957 9799 1156 2378 9172 7374 1683 6717 3461 9831 3949 4752 5885 4804 6771 7019 9537 3243 9279 9409 8567 8073 5661 2269 832 5327 1498 1801 9174 8725 9684 9321 384 3022 3219 9506 2905 1447 9255 1287 4218 9970 4036 434 4035 6990 1691 9727 797 3554 5740 5037 69...
output:
249713496095 251572960796 273358652179 250203360837 249684467947 249981649507 256702986698 258493281910 251000913650 257529116634 257762386417 258553080396 249554932547 256082039347 249089871945 251085141439 263148407860 249766603398 250076696380 250585794082 250421078709 249441934428 251687038471 2...
result:
ok 100000 lines
Test #22:
score: 0
Accepted
time: 37ms
memory: 6388kb
input:
10000 100000 5596 1361 4177 2969 4355 8459 5010 3699 6335 8066 9340 7488 3129 3500 1550 2735 6139 6311 1504 5031 1831 1349 5234 4465 7206 6731 9583 3538 383 8343 1547 3416 5308 3775 1760 3069 4314 9538 7686 2688 2856 3087 9088 3517 8379 2840 8940 9458 2228 6283 7144 1302 8282 8424 6128 5603 2415 408...
output:
250990807036 262710849036 265081133260 250000268787 256020932279 255232771257 249100138964 263257267194 249194046449 262557677158 260603239728 250101620353 250120327286 255811800712 276237681179 276270565452 249227287708 260665939511 249400765380 260367472355 253075178167 251540474368 249470146114 2...
result:
ok 100000 lines
Test #23:
score: 0
Accepted
time: 26ms
memory: 6368kb
input:
10000 100000 7978 1405 715 1391 6719 9230 8184 5401 3695 4139 6776 4122 2997 1436 1806 3918 1612 8203 3579 3902 1312 2819 3506 6477 9228 1664 5987 9908 7785 1477 6072 5474 3824 7599 9591 6462 4068 5883 9574 6566 3963 6043 45 946 43 5263 526 3201 2429 8981 6782 1077 2842 1875 4124 7630 919 4623 8254 ...
output:
333383335000 333383335000 333383335000 250535430898 333383335000 250535430898 333383335000 333383335000 250535430898 333383335000 333383335000 333383335000 250535430898 333383335000 250535430898 333383335000 333383335000 250535430898 333383335000 250535430898 333383335000 250535430898 250535430898 2...
result:
ok 100000 lines
Test #24:
score: -100
Wrong Answer
time: 198ms
memory: 81728kb
input:
100000 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 ...
output:
333333333399999 333328333549999 333323333799999 333318334149999 333313334599999 333308335149999 333303335799999 333298336549999 333293337399999 333288338349999 333283339399999 333278340549999 333273341799999 333268343149999 333263344599999 333258346149999 333253347799999 333248349549999 333243351399...
result:
wrong answer 1st lines differ - expected: '333333333400000', found: '333333333399999'