QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292147 | #5830. 树 | for_to | 0 | 1246ms | 94312kb | C++14 | 1.7kb | 2023-12-27 19:43:29 | 2023-12-27 19:43:29 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define N 1000005
using namespace std;
int n,q;
int a[N],b[N],v[N];
int sum[N],f[N][22];
vector <pair <int,int> > g[N];
int ans[N];
signed main(){
cin.tie(0); ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=2,p;i<=n;i++) cin>>p;
cin>>q;
for(int i=1,x,k;i<=q;i++){
cin>>x>>k;
g[x].pb(make_pair(k,i));
}
for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end());
// 0101
// 00110011
// 00001111
for(int k=0;k<=30;k++){
for(int i=1;i<=n;i++){
a[i]=(v[i]>>k)&1ll;
b[i]=(((i-1)/(1ll<<k)+1)&1ll)^1ll;
a[i]^=b[i];
sum[i]=sum[i-1]+a[i];
}
for(int l=1;l<=n;l++){
for(int i=0;i<g[l].size();i++){
int r=l+g[l][i].fi;
ans[g[l][i].se]+=((sum[r]-sum[l-1])*(1ll<<k));
}
}
// for(int i=1;i+(1ll<<k)-1<=n;i++) f[i][0]=sum[i+(1ll<<k)-1]-sum[i-1];
// for(int i=1;(1ll<<(i+k))<=n;i++)
// for(int j=1;j+(1ll<<(i+k))-1<=n;j++){
// if(i==1) f[j][i]=f[j][i-1]+((1ll<<k)-f[j+(1ll<<k)][i-1]);
// else f[j][i]=f[j][i-1]+f[j+(1ll<<(i+k-1))][i-1];
// }
//
// for(int l=1;l<=n;l++){
// for(int i=0;i<g[l].size();i++){
// int r=l+g[l][i].fi;
//
// int x=l,res=0;
// bool fl=0;
// for(int j=20;j>=0;j--)
// if(x+(1ll<<(j+k))-1<=r){
// fl^=((1ll<<j)&1ll);
// res+=f[x][j];
// x+=(1ll<<(j+k));
// }
// if(x<=r){
// int len=r-x+1;
// if(!fl) res+=(sum[r]-sum[x-1]);
// else res+=(len-(sum[r]-sum[x-1]));
// }
//
// ans[g[l][i].se]+=(res*(1ll<<k));
// }
// }
}
for(int i=1;i<=q;i++) cout<<ans[i]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 36420kb
input:
2000 946347867 341162491 202762650 295215762 254064439 66267204 693162580 357612557 492940637 939526638 59775103 374919339 144042807 861369313 651043728 999024805 439554916 167782038 597475252 56704409 69846137 22185655 79439847 769194737 145071391 226046618 915359433 392527325 84982946 54584098 827...
output:
16836874934 1346229849 281360730 123852676424 39316719762 1259618683 1283396065 1397309471 3260130861 19554525542 518706471 1444504087 21095973916 1754071900 48246034330 33395741067 53461548289 1421778573 60369883302 848546943 1934239254 9793050221 1278556464 45397794323 965921535 304775954 26674238...
result:
wrong answer 1st numbers differ - expected: '31727996563', found: '16836874934'
Test #2:
score: 0
Wrong Answer
time: 84ms
memory: 46128kb
input:
99999 792064428 473106195 799314986 65440734 948726345 442414256 280245405 873012700 466192412 899092866 283555341 657824017 963883713 793944180 767444438 105576842 542107696 580140098 65321660 381184238 584604194 397414881 861590124 309323011 217641157 120832524 303744205 961590116 110259426 380351...
output:
2406872116 43304481012 520932031 1101884630 1755025765 991664407363 2046547582897 1035945289 1600673979597 1763127439 633879919 401400243 141080692 1020778084 1327049197263 4422115596835 1328124127 1645107205 596013340639 2580531812730 1202687585 1351293507 591907060473 1668300497 917293439376 16696...
result:
wrong answer 1st numbers differ - expected: '2509771019', found: '2406872116'
Test #3:
score: 0
Wrong Answer
time: 1175ms
memory: 93676kb
input:
1000000 947727010 179844140 923847675 171881267 5552129 974443359 989307850 869400987 126992154 527448411 141137718 136124474 917813105 392020809 79012342 473860575 969007624 833563354 90169336 878445705 84352622 403307122 733751738 670851448 942399068 731541999 101293644 545785337 964751520 9168003...
output:
322287974043616 64144632364169 131621619420426 185914369921809 4835910746685 52498330854028 91107166899288 133548835260890 287850507534576 123170801561829 128593125393936 8701356627650 14021780635413 65043919354276 310510431044293 15605702320717 75072091148898 73630078004704 66820861921263 217424420...
result:
wrong answer 1st numbers differ - expected: '322288180595345', found: '322287974043616'
Test #4:
score: 0
Wrong Answer
time: 1246ms
memory: 93436kb
input:
1000000 264862971 751386013 921867736 711577153 262726588 565608444 975324815 440219681 107888226 928241413 729126923 283912914 86248857 896446999 12839598 651796991 139813366 105131395 341646170 839485925 939265720 844548518 102280410 457829889 8602879 737140565 17206920 974175632 535833885 8373832...
output:
1437276181397 97809440942883 338628280647261 233680483985157 7398855023332 271306085488436 20877435818660 90775254872479 2535114311795 66604642545254 211534437280954 84757485605079 17886176845747 132051770185871 1860367995072 46254060682367 83950910299568 257274391283915 240943272991589 118446683120...
result:
wrong answer 1st numbers differ - expected: '1437301063221', found: '1437276181397'
Test #5:
score: 0
Wrong Answer
time: 1086ms
memory: 93452kb
input:
1000000 978606419 773027389 111265179 979476504 280718851 476857501 751854950 579263969 848569548 781051974 31782627 533831186 812822170 111553645 297770650 331144396 676977983 2236128 258203325 75591120 676466973 60056446 494411414 286185093 92474576 173276071 535648669 87210101 355790411 880267291...
output:
715563904 1367365160 1598328999 6839568915 6082972547 1681026422 5572345675 1698012166 1174130472 599705028 1950637704 1561892153 7161720608 262922282 592662988 1041196624 1339018322 2309160154 832211537 8691301162 2878630523 4232428011 1207404652 7742862977 433841938 594358387 575222134 962938045 1...
result:
wrong answer 1st numbers differ - expected: '2258826661', found: '715563904'
Test #6:
score: 0
Wrong Answer
time: 1208ms
memory: 94312kb
input:
1000000 952470566 585754087 120174600 401525004 458588768 5487567 31210348 446333263 231409083 521960132 457721893 866842852 925207283 16805978 4706826 99640835 619272676 136536623 459247161 308807462 633687300 717271369 23906473 865522890 173799280 424309108 719410673 118906385 110627845 730629403 ...
output:
917333086051557680 258926210529064590 19893542135955864 18747315433291961 1920893782340924154 1601993467291663515 628282027566249395 1781500460512698793 1203901219396321492 509898684815043298 554057933576844938 1102057313203718500 1233272709428273629 331280706146580710 1558702253721480943 1376182353...
result:
wrong answer 1st numbers differ - expected: '994051214', found: '917333086051557680'
Test #7:
score: 0
Wrong Answer
time: 1160ms
memory: 93188kb
input:
1000000 732367509 105027907 958920212 886798715 102486738 813075884 301085392 242303497 979657287 944859684 307768 438158233 561755409 740706505 791145209 283862713 828081846 771569552 59044985 600549571 191330226 438693570 36976319 810654215 220068818 771875421 740642902 839964155 206129566 2065543...
output:
1089154386385871499 4849283562060 1078694853369086991 705092471517404075 754272232932243124 309736447342608554 73987409759346110 70121415418342067 431344400726014360 225889516085539249 521565251792919094 1206363985454919754 1061420901683360103 990232881337128407 215522341624393506 957191198415148 57...
result:
wrong answer 1st numbers differ - expected: '999908753', found: '1089154386385871499'
Test #8:
score: 0
Wrong Answer
time: 1114ms
memory: 94220kb
input:
1000000 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 ...
output:
44082373440 38032360116 3303848808 3890061 62895247492 1687991091 909443 10180145732 110539239 395085 467566 831785 2766591 2895135 1180923 999039 1825773411 695681 382925 30722582979 551758 711021 1685169 1233912 1348045 14343270629 2238513 1136777 1939913 244879 1912217 10923516045 15941099481 853...
result:
wrong answer 1st numbers differ - expected: '3826404725', found: '44082373440'
Test #9:
score: 0
Wrong Answer
time: 1183ms
memory: 93484kb
input:
1000000 465660691 982007525 816592310 377030959 572981469 679249520 86377999 709561525 940473306 35102782 886143915 792819787 903287397 264564177 857982095 91486434 217197704 123118964 383387342 820268798 497623987 255010796 607884194 848568529 38169627 197987657 421323589 664004905 485409127 696844...
output:
41182573460 3288930600102 33077754706566 13778800887349 996854337 1797965362 882662855 4705324705626 4048466533364 116196869336 6326971873752 1472760969 1457342413 1202024694 5127770501721 273888826 11351608588535 259151093 363385638 19512183097572 24851024828942 574083542 7134810107682 997139682 92...
result:
wrong answer 1st numbers differ - expected: '96094116015', found: '41182573460'
Test #10:
score: 0
Wrong Answer
time: 1201ms
memory: 92728kb
input:
1000000 665830082 788228483 245541444 289601309 641764988 150723484 925214020 557415731 310210969 379707835 517820381 883917428 134445288 775557009 444476671 89856268 655841087 888410254 37788122 694551869 563331754 488108584 839551943 415095075 445425438 35452604 562044723 640544531 146258096 66852...
output:
1049473308 701930429 27331263110802 2882892996708 19688729176163 5522662717177 1164646523 2000648744261 1239917331 429650594 1067048495419 10214012691437 1524844768 869474399 29997392772647 1107926898 12499189219365 2725763332 1987608961078 934286096 7482392252323 1012853160 3569246490625 2287397168...
result:
wrong answer 1st numbers differ - expected: '431856043', found: '1049473308'