QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281154#7765. Xor Mastersongziyan0 231ms27008kbC++143.4kb2023-12-09 22:28:052023-12-09 22:28:07

Judging History

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

  • [2023-12-09 22:28:07]
  • 评测
  • 测评结果:0
  • 用时:231ms
  • 内存:27008kb
  • [2023-12-09 22:28:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int N=1e5+5;
int n,q;
ull a[N],g[N];
struct basis{
	ull s[70];
	ull insert(ull x){
		for(int i=63;i>=0;i--)if((x>>i)&1){
			if(!s[i]){
				for(int j=i-1;j>=0;j--)
					if((x>>j)&1)x^=s[j];
				s[i]=x;
				for(int j=63;j>i;j--)
					if((s[j]>>i)&1)s[j]^=x;
				return x;
			}
			x^=s[i];
		}
		return 0;
	}
	ull qrymin(ull x){
		for(int i=63;i>=0;i--)x=min(x,x^s[i]);
		return x;
	}
	ull qrymax(ull x){
		for(int i=63;i>=0;i--)x=max(x,x^s[i]);
		return x;
	}
}bas;
struct bit{
	ull a[N];
	void add(int x,ull v){
		for(;x<=n;x+=(x&(-x)))
			a[x]^=v;
	}
	ull sum(int x){
		ull res=0;
		for(;x;x-=(x&(-x)))	
			res^=a[x];
		return res;
	}
	void init(){
		memset(a,0,sizeof(a));
	}
}c;
struct tree{
	#define lc x<<1
	#define rc x<<1|1
	ull tmp[N<<4],*p=tmp;
	ull *tr[N<<2],tag[N<<2];//,sum[N<<2];
	int tot[N<<2],len[N<<2];
	void pushup(int x){
		ull k=0;
		for(int i=0;i<tot[x];i++){
			tr[x][i]=tr[lc][i]^tr[rc][i]^k;
			k=(tr[lc][i]&tr[rc][i])|(tr[lc][i]&k)|(tr[rc][i]&k);
		}
		//sum[x]=sum[lc]+sum[rc];
	}
	void addtag(int x,ull v){
		tag[x]^=v;
		//sum[x]=0;
		ull k=0;
		for(int i=0;i<tot[x];i++){
			ull t=k;
			if((len[x]>>i)&1){
				k=k&(tr[x][i]&v);
				tr[x][i]=tr[x][i]^t^v;
			}else{
				k=k|(tr[x][i]&v);
				tr[x][i]=tr[x][i]^t;
			}
			//sum[x]+=(tr[x][i]<<i);
		}
	}
	void pushdown(int x){
		if(tag[x]){
			addtag(lc,tag[x]);
			addtag(rc,tag[x]);
			tag[x]=0;
		}
	}
	void build(int x,int l,int r){
		tag[x]=0;
		len[x]=r-l+1;
		while((1<<tot[x])<=(r-l+1))++tot[x];
		tr[x]=p;p+=tot[x]+5;
		if(l==r){
			tr[x][0]=/*sum[x]=*/bas.qrymax(g[l]);
			//printf("%llu ",tr[x][0]);
			return;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pushup(x);
	}
	void upd(int x,int l,int r,int ql,int qr,ull v){
		if(!v)return;
		if(ql<=l&&r<=qr)return addtag(x,v);
		pushdown(x);
		int mid=(l+r)>>1;
		if(ql<=mid)upd(lc,l,mid,ql,qr,v);
		if(qr>mid)upd(rc,mid+1,r,ql,qr,v);
		pushup(x);
	}
	ull qry(int x,int l,int r,int ql,int qr){
		if(ql<=l&&r<=qr){
			ull res=0;
			for(int i=0;i<tot[x];i++)
				res+=(tr[x][i]<<i);
			return res;
		}
		pushdown(x);
		int mid=(l+r)>>1;
		ull res=0;
		if(ql<=mid)res+=qry(lc,l,mid,ql,qr);
		if(qr>mid)res+=qry(rc,mid+1,r,ql,qr);
		return res;
	}
	void rbuild(int x,int l,int r){
		tag[x]=0;
		if(l==r){
			tr[x][0]=/*sum[x]=*/bas.qrymax(g[l]);
			return;
		}
		int mid=(l+r)>>1;
		rbuild(lc,l,mid);
		rbuild(rc,mid+1,r);
		pushup(x);
	}
}T;
void init(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%llu",&a[i]);
	for(int i=1;i<=n;i++){
		g[i]=g[i-1]^a[i];
		c.add(i,a[i]);
	}
	T.build(1,1,n);
}
void opt1(int x,ull v){
	a[x]^=v;
	c.add(x,v);
	T.upd(1,1,n,x,n,bas.qrymin(v));
}
void opt2(ull v){
	if(bas.insert(v)){
		c.init();
		for(int i=1;i<=n;i++){
			g[i]=g[i-1]^a[i];
			c.add(i,a[i]);
		}
		T.rbuild(1,1,n);
	}
}
ull opt3(int ql,int qr){
	ull pre=c.sum(ql-1);
	ull v=bas.qrymin(pre);
	T.upd(1,1,n,ql,qr,v);
	ull ans=T.qry(1,1,n,ql,qr);
	T.upd(1,1,n,ql,qr,v);
	return ans;
}
signed main(){
	init();
	//printf("%llu\n",T.qry(1,1,n,1,2));
	while(q--){
		int op,x,l,r;ull v;
		scanf("%d",&op);
		if(op==1){
			scanf("%d%llu",&x,&v);
			opt1(x,v);
		}
		if(op==2){
			scanf("%llu",&x);
			opt2(x);
		}
		if(op==3){
			scanf("%d%d",&l,&r);
			printf("%llu\n",opt3(l,r));
		}
	}
	return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 4ms
memory: 10792kb

input:

2000 2000
1860495733 462603674 3739839441 759356520 47330263 550811730 2301200895 989240351 2499503801 2624225494 2123076812 1180966826 238739434 488666688 784742950 2583466952 4111371941 2335988605 2583741355 933716686 1644403538 1970423306 304500250 905101643 1814942168 1136358764 88729799 1577263...

output:

867006634793
3418049036989
1658469159497
794670034691
239792547603
1587489101990
592222190840
1343829229567
971235609706
571701308760
1219913933321
588622962923
2129364200509
1007100395808
3134493164996
3145027621038
2599298085956
1729302186341
837940435945
242569415869
2908005634977
1692554597386
1...

result:

ok 1001 lines

Test #2:

score: -10
Wrong Answer
time: 4ms
memory: 10728kb

input:

2000 2000
836488286 497338588 1858847699 3099907357 1601878363 409027819 646677017 3314413779 3312383261 4245381929 661740170 2016795844 1226219370 1347593623 4008424282 2941543248 1331853899 3217984002 3651447350 1223595274 1733763258 2829453991 3934056384 2556266950 326379115 3240694642 2405972228...

output:

1042755994488
3566460727022
18446740745952826057
18446743959848809881
18446740509895907115
18446743987370155594
18446741443559482131
18446743635423780987
18446742165024536324
18446741311854446040
18446743813645612656
18446741553430740551
18446743204154229241
18446743171666784844
18446743152320260326...

result:

wrong answer 3rd lines differ - expected: '4896344756993', found: '18446740745952826057'

Subtask #2:

score: 0
Runtime Error

Test #5:

score: 0
Runtime Error

input:

500000 100000
12261386944926786495 7846697792998647383 16622924885320463714 170129022271213944 12625257523700625864 7684671687986103560 11532026873918423068 1131776055566669037 8263146651412710501 17872572061246021001 5017109039248728310 11088626167542318645 13810119722795416818 10928315716094262229...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 231ms
memory: 27008kb

input:

100000 100000
860905160 3192911636 290327446 2020707113 959258245 454185039 421895589 1070265496 2218913641 1684685660 1206723673 2606734467 4247254571 3341954386 3805299640 1702270353 2472053741 2816060613 1307901348 2702949728 879391505 884661815 330738731 1575749344 1239158446 2099693858 67466644...

output:

208755389215975
125497785366837
162446748431411
63166834945113
33018804920229
89343160639243
36805816758195
40790494641758
13928126471189
267168502433672
191989403472418
276350936750564
11189666657474
133862444125402
92684260245650
179275392898572
46159208957881
232612971657325
184946588056252
11022...

result:

wrong answer 95th lines differ - expected: '258562763363052', found: '18446657840664127451'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%