QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292145 | #5830. 树 | for_to | 0 | 1135ms | 94580kb | C++14 | 1.7kb | 2023-12-27 19:41:54 | 2023-12-27 19:41:54 |
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<=20;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=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: 3ms
memory: 34432kb
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:
-1015507334 -312595007 -1675636082 176321723 -1208681780 -279342270 -471659673 -122282755 -1246327122 -295235280 -39351672 -115520635 -1568933191 -1358023545 -1656315081 -1526696189 -35060310 -599811980 -408941579 -48957127 -1790095599 -1381198319 -1331484492 -1609743968 -1946794199 -376989968 -1817...
result:
wrong answer 1st numbers differ - expected: '31727996563', found: '-1015507334'
Test #2:
score: 0
Wrong Answer
time: 80ms
memory: 46124kb
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:
-42638253027 -50113606381 -16227606003 -4344806657 -45239892955 -70011994751 -60689852912 -98066892808 -27313784589 -51911460115 -77335448417 -34051436381 -61521429859 -8742899824 -85931947065 1394354362 -47785623821 -73231188565 -12602454953 -2734796649 -85780773863 -38902550262 -36718888911 -69291...
result:
wrong answer 1st numbers differ - expected: '2509771019', found: '-42638253027'
Test #3:
score: 0
Wrong Answer
time: 1135ms
memory: 94560kb
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:
563762255762 -601958094386 -445894162887 194298427239 -1022255092190 -225125636745 88208339089 -403216807541 324299703256 -190186767804 105141614820 -988156470905 -80788563829 -125218053161 400785213107 -928507558775 -451860466550 -492719592954 -614397415647 -934156639654 -355114174176 49637016897 -...
result:
wrong answer 1st numbers differ - expected: '322288180595345', found: '563762255762'
Test #4:
score: 0
Wrong Answer
time: 1117ms
memory: 93976kb
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:
-1030528358857 -156816076250 680698158782 30132586723 -894676185593 479528623626 -605583765820 -269112251648 -981531588515 -572537421705 397138717863 -132805664518 -955874581941 189394216550 -894755972361 -708498698186 133074376177 435689265830 449318148666 -364217155579 17662830984 -621792504130 -8...
result:
wrong answer 1st numbers differ - expected: '1437301063221', found: '-1030528358857'
Test #5:
score: 0
Wrong Answer
time: 1018ms
memory: 94580kb
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:
-761938828980 -621815791436 -58138472021 -429844278188 -406900576761 -75934784358 -456963171475 -27159862180 -837760121958 -126689393662 -692383242927 -260993721482 -545081646442 -232627847768 -497314273136 -486893368283 -1006755410499 -318349691970 -596720438707 -968816142036 -905421235068 -7242067...
result:
wrong answer 1st numbers differ - expected: '2258826661', found: '-761938828980'
Test #6:
score: 0
Wrong Answer
time: 989ms
memory: 94432kb
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:
991746528440 1047004920270 95329378534 795371552449 602955193916 453120046547 689861724934 326990986127 988364498826 364974448474 147631465040 407588152623 120258150552 496254212609 292860793104 1041790252607 141356906035 1017443167115 729367221545 743370498596 26941412711 849406732376 61007963506 8...
result:
wrong answer 1st numbers differ - expected: '994051214', found: '991746528440'
Test #7:
score: 0
Wrong Answer
time: 1040ms
memory: 94068kb
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:
727650928837 182035103298 721824668992 694439997547 126793665586 501930329589 1033393264664 224209322361 39085296750 583448096687 830393939412 977279573404 698633117790 282917258762 426998596370 423588224031 391645711828 158210679860 115157981700 928750016605 482413916133 195565792822 473406563955 8...
result:
wrong answer 1st numbers differ - expected: '999908753', found: '727650928837'
Test #8:
score: 0
Wrong Answer
time: 967ms
memory: 94192kb
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:
-293488988085 -164833318550 -272221645550 -154412081325 -309357410331 -26779511777 -103385366560 -189196088653 -123909116081 -19511322111 -6831577602 -86482869886 -425222270109 -465654478445 -77476027979 -124759365921 -4876636032 -60496158880 -18328752991 -174789230060 -9513376950 -63193502295 -3549...
result:
wrong answer 1st numbers differ - expected: '3826404725', found: '-293488988085'
Test #9:
score: 0
Wrong Answer
time: 984ms
memory: 93060kb
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:
-1047017332791 -712734539308 -751206226728 -291410175913 -187994389198 -640201945330 -999710023013 -698234957898 -675497223489 -778742943157 -177719959847 -965258431051 -614900596375 -826707086892 -993183043863 -827003200273 -921443311269 -840895312191 -645032106234 -623735114091 -133290628110 -8053...
result:
wrong answer 1st numbers differ - expected: '96094116015', found: '-1047017332791'
Test #10:
score: 0
Wrong Answer
time: 1007ms
memory: 93580kb
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:
-950183055696 -357100624825 -272977739588 -497924783418 -342746288369 -734782283225 -652155492570 -167919105411 -574880083748 -694813620302 -1026005778130 -679485409805 -1001098788597 -686116034075 -814341160216 -96774886507 -545373985864 -787803982933 -175682367997 -394568001233 -199572924779 -7176...
result:
wrong answer 1st numbers differ - expected: '431856043', found: '-950183055696'