QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292146#5830. 树for_to0 1048ms94292kbC++141.7kb2023-12-27 19:42:282023-12-27 19:42:29

Judging History

你现在查看的是最新测评结果

  • [2023-12-27 19:42:29]
  • 评测
  • 测评结果:0
  • 用时:1048ms
  • 内存:94292kb
  • [2023-12-27 19:42:28]
  • 提交

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=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: 3ms
memory: 36484kb

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:

34493110
1955417
2439514
277994824
81102994
1327483
2036193
2703391
7448109
46817638
2807079
3760663
46859292
2949980
110104474
78287243
122584321
2006669
129192102
3394687
2762262
22419053
1390896
103505427
1231615
688914
2501237
528767
44758378
1719666
7106719
2377182
4319171
5706785
1601825
13727...

result:

wrong answer 1st numbers differ - expected: '31727996563', found: '34493110'

Test #2:

score: 0
Wrong Answer
time: 72ms
memory: 43828kb

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:

5633076
90566900
838335
2976982
1806693
2236482371
4529708977
2049353
3483016397
3616911
2637167
2941363
2668660
1562212
2940978895
9911212579
2724063
3037189
1340725215
5774416250
3116641
2824771
1321794297
1064657
1991448976
4553477
5426708
1882329
1516509
1975673
199140334
2123689
1748432
7119656...

result:

wrong answer 1st numbers differ - expected: '2509771019', found: '5633076'

Test #3:

score: 0
Wrong Answer
time: 997ms
memory: 92676kb

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:

717432901600
142692760713
292990930186
414082290449
10852631101
117152981644
202753821784
297435056602
641288110320
274112426213
286572627472
19375937218
31407013653
144780376484
691585221317
34747179597
167089754722
163701911008
148725630959
48182693582
298400020852
519534605066
273017010827
344562...

result:

wrong answer 1st numbers differ - expected: '322288180595345', found: '717432901600'

Test #4:

score: 0
Wrong Answer
time: 1048ms
memory: 94292kb

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:

3126203285
217235303203
753055891037
519233677061
16332626660
603450890036
46601163428
201736728991
5575706739
148292709990
469935975610
187945865431
39698538419
293919692943
4099068096
102888062079
186410589616
572301494475
535613840229
263781409449
227278265735
85773213167
11335261402
308414962899...

result:

wrong answer 1st numbers differ - expected: '1437301063221', found: '3126203285'

Test #5:

score: 0
Wrong Answer
time: 880ms
memory: 93072kb

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:

2532224
2119208
2396327
17533459
11717507
1207670
10698571
5610502
1822504
2016708
2383496
3708217
14626592
778282
1266124
3106384
3132498
4390106
3836497
21674794
7629435
8763883
3639404
21149313
1828626
864371
4796790
2442429
1372598
5868549
2077548
14327452
1877210
2459752
2790007
8467839
3078073...

result:

wrong answer 1st numbers differ - expected: '2258826661', found: '2532224'

Test #6:

score: 0
Wrong Answer
time: 986ms
memory: 93592kb

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:

895800820425008
252856680543886
18892432245144
18165862285497
1875621736084218
1564111595535515
613355041142195
1739340672524713
1175650491105492
497563848862434
540566367876746
1075867335854436
1203846425076189
323206064814310
1521745201426159
134389007376544
1596254267529691
2005635651177069
11729...

result:

wrong answer 1st numbers differ - expected: '994051214', found: '895800820425008'

Test #7:

score: 0
Wrong Answer
time: 968ms
memory: 94232kb

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:

1063447078281867
-481609713076
1053229416399887
688368119241643
736076280755892
302170194378922
72245127847358
68015230577331
420667977677208
220334215360945
509218730662454
1178049670115402
1036347290874215
966594318751191
210122149113634
584033573164
556667200783686
1745369287898524
14669129395662...

result:

wrong answer 1st numbers differ - expected: '999908753', found: '1063447078281867'

Test #8:

score: 0
Wrong Answer
time: 970ms
memory: 94044kb

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: 969ms
memory: 93132kb

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:

82588564
7456048294
73833495174
30633641525
707137
2803250
1859015
10633946970
8986876916
262112472
14017968600
2657417
4016077
2453750
11482985049
1259066
25263929591
1201397
578342
43362683108
55597718030
1561046
15891328802
992482
2103448508
25160218093
1471177
317767840
1739628
11695848646
31508...

result:

wrong answer 1st numbers differ - expected: '96094116015', found: '82588564'

Test #10:

score: 0
Wrong Answer
time: 999ms
memory: 93972kb

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:

2994460
1481661
60861095570
6359621732
43685079139
12326631161
2824315
4545916229
2597651
1831586
2399922491
22803981293
4409568
1253471
66726182439
2727794
27793276965
3660036
4407812150
3150608
16478703523
2025896
8091553793
5024703537
3787988
3113935
2292036
23403402260
657063
3873012
12943640348...

result:

wrong answer 1st numbers differ - expected: '431856043', found: '2994460'