QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470713#5022. 【模板】线段树DaiRuiChen0070 3ms15684kbC++172.2kb2024-07-10 16:01:222024-07-10 16:01:24

Judging History

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

  • [2024-07-10 16:01:24]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:15684kb
  • [2024-07-10 16:01:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1<<18,B=2;
int a[MAXN],w[MAXN],bel[MAXN],lp[MAXN],rp[MAXN],len[MAXN];
//w[i]: a[ed[x]] after oper i-lp[x] times
vector <int> tag[MAXN];
void init(int x) { //build block x
//	cerr<<"init "<<x<<"\n";
	int n=len[x],*f=w+lp[x];
	for(int i=0;i<n;++i) f[i]=a[rp[x]-i];
	for(int k=1;k<n;k<<=1) for(int i=0;i<n;++i) if(i&k) f[i]^=f[i^k];
//	cerr<<"Arr = "; for(int i=lp[x];i<=rp[x];++i) cerr<<a[i]<<" "; cerr<<"\n";
//	cerr<<"Ans = "; for(int i=0;i<n;++i) cerr<<f[i]<<" "; cerr<<"\n";
//	cerr<<"\n";
}
void psd(int x) { //pushdown block x
	vector <int> &g=tag[x];
//	cerr<<"push down "<<x<<"\n";
	int n=len[x],m=g.size(),*f=a+lp[x];
//	cerr<<"oper times = "<<m<<"\n";
	for(int k=1;k<n&&k<=m;k<<=1) if(m&k) {
		for(int i=n-1;i>=k;--i) f[i]^=f[i-k];
	}
	reverse(g.begin(),g.end());
	for(int k=1;k<m;k<<=1) for(int i=0;i<m;++i) if(i&k) g[i^k]^=g[i];
	for(int i=0;i<n&&i<m;++i) f[i]^=g[i];
	g.clear();
//	cerr<<"get = "; for(int i=0;i<n;++i) cerr<<f[i]<<" "; cerr<<"\n";
}
int qed(int x) { //qry a[rp[x]]
	int n=len[x];
	if((int)tag[x].size()>=n) psd(x),init(x);
//	cerr<<"query end = "<<w[lp[x]+tag[x].size()]<<"\n";
	return w[lp[x]+tag[x].size()];
}
int qry(int i) {
	psd(bel[i]),init(bel[i]);
	return a[i];
}
void opr(int l,int r) {
	if(bel[l]==bel[r]) {
		psd(bel[l]);
		for(int i=r;i>bel[l];--i) a[i]^=a[i-1];
		return init(bel[l]);
	}
	psd(bel[r]);
	for(int i=r;i>lp[bel[r]];--i) a[i]^=a[i-1];
	a[lp[bel[r]]]^=qed(bel[r]-1);
	init(bel[r]);
	for(int i=bel[r]-1;i>=bel[l]+1;--i) tag[i].push_back(qed(i-1));
	psd(bel[l]);
	for(int i=rp[bel[l]];i>l;--i) a[i]^=a[i-1];
	init(bel[l]);
}
signed main() {
	ios::sync_with_stdio(false);
	int _,n,m;
	cin>>_>>n>>m;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;rp[i-1]<n;++i)  {
		lp[i]=rp[i-1]+1,rp[i]=min(n,lp[i]+B-1);
		fill(bel+lp[i],bel+rp[i]+1,i),len[i]=rp[i]-lp[i]+1;
		init(i);
//		cerr<<"Block "<<i<<" = ["<<lp[i]<<" "<<rp[i]<<"]\n";
	}
	for(int op,l,r,x;m--;) {
		cin>>op;
		if(op==1) cin>>l>>r,opr(l,r);
		else cin>>x,cout<<qry(x)<<"\n";
	}
	for(int i=1;i<=bel[n];++i) psd(i),init(i);
	for(int i=1;i<=n;++i) cout<<a[i]<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 0ms
memory: 15604kb

input:

1
6 6
1 1 5 1 9 4
2 5
1 2 5
2 4
1 3 6
2 6
1 1 6

output:

9
4
12
1
0
5
4
12
0

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 12200kb

input:

1
999 997
898798734 979577086 45974352 1013270193 1053191143 533594258 372426673 947830633 122319874 368651315 866424479 109724831 427664962 558099346 764830489 326451620 322471751 525780385 746941281 670254345 586958579 979544209 743892216 436404384 291681381 979530194 998929567 367716728 909076993...

output:

1015342581
962986689
965094083
871356796
835210392
172023195
63088572
606096781
569607283
436055720
154605892
663158209
154605892
776365236
281312240
62398687
182713417
604764772
816533315
793514230
325061861
806973284
91749226
283750235
198953311
170342298
432592070
809908556
683302450
40932811
669...

result:

ok 1996 numbers

Test #3:

score: -8
Wrong Answer
time: 3ms
memory: 15684kb

input:

1
999 997
89872218 906651903 120274311 490547919 291584020 755757065 24942887 707247173 763024744 68250332 114193028 999245166 140381610 171802205 399965713 299821903 907998064 906075056 427270276 335420206 708713870 492555323 359637714 197212814 35225369 1011322274 912003632 633998134 1026276199 85...

output:

89872218
860962725
120274311
490547919
978745892
924706625
610771729
524956121
105748312
139294727
866385688
729638611
92178006
1037482711
80194776
277477501
592738191
694314356
733017733
701758468
65199929
983529101
717179143
542164040
444291361
439952700
147939819
276321083
1012586084
166061298
30...

result:

wrong answer 323rd numbers differ - expected: '595964248', found: '1036207028'

Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

2
249998 99999
1048488450 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #10:

score: 0
Time Limit Exceeded

input:

3
250000 99999
1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1...

output:

0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
1
0
0
0
0
1
1
0
1
1
0
1
0
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
0
1
0
0
0
1
1
0
1
0
0
1
1
0
1
0
0
0
0
1
1
1
0
1
1
0
0
0
1
1
0
1
0
1
1
0
1
0
1
1
0
1
1
0
0
1
0
1
0
1
0
1
1
1
1
0
0
0
1
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
0
1
1
0
1
1
1
0
0
1
1
1
0
0
0
1
0
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
0
...

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

input:

4
249996 99997
309331355 195839266 912372930 57974187 363345291 954954162 650621300 389049294 821214285 263720748 231045308 844370953 768579771 664766522 681320982 124177317 32442094 297873605 743179832 1073656106 443742270 235746807 1054294813 974443618 422427461 307448375 1018255356 20105813 36821...

output:

611117059
866091251
300188933
0
478915924
1053588351
453142424
897441996
60971719
748656483
600408393
0
303761852
983037069
883016404
332332552
1069626159
860304528
851235295
561276840
389049294
681320982
484263000
351914192
620106464
667080579
733146026
375466744
0
347632358
737240082
321494160
0
3...

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #18:

score: 0
Time Limit Exceeded

input:

5
249997 99997
860563869 428592873 58576739 761578583 47999879 294581118 988847649 569566599 640106250 440172702 178219106 966598261 763325707 846927552 877923116 145156535 246778542 25949847 507939778 116507169 555239769 259969305 328955819 171606729 535970481 121608060 4437163 370976515 713807003 ...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%