QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283110#7765. Xor Mastermaoyiting0 382ms58640kbC++142.5kb2023-12-13 20:50:512023-12-13 20:50:51

Judging History

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

  • [2023-12-13 20:50:51]
  • 评测
  • 测评结果:0
  • 用时:382ms
  • 内存:58640kb
  • [2023-12-13 20:50:51]
  • 提交

answer

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int N=5e5+5,M=N<<2;
int n,m,len[M],op,x,l,r;
ll v,a[N],s[N],c[N],b[N],*val[M],tg[M],tmp[N<<3],*id=tmp;
void upd(int p,ll v){
	tg[p]^=v;
	ll x=0;
	for(int i=0;i<len[p];i++){
		if(len[p]>>i&1)
			tie(val[p][i],x)=make_pair(val[p][i]^v^x,x&val[p][i]&v);
		else
			tie(val[p][i],x)=make_pair(val[p][i]^x,(x|val[p][i])&v);
	}
}
void down(int p){
	if(tg[p]) upd(p<<1,tg[p]),upd(p<<1|1,tg[p]),tg[p]=0;
}
void push(int p){
	ll x=0,*lc=val[p<<1],*rc=val[p<<1|1];
	for(int i=0;i<len[p];i++)
		val[p][i]=lc[i]^rc[i]^x,
		x=(lc[i]&rc[i])|(lc[i]&x)|(rc[i]&x);
}
void build(int p,int l,int r){
	while((1<<len[p])<=r-l+1) len[p]++;
	val[p]=id,id+=len[p]+1;
	if(l==r){val[p][0]=s[l];return ;}
	int mid=(l+r)/2;
	down(p);
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	push(p);
}
void reset(int p,int l,int r){
	if(l==r){val[p][0]=max(val[p][0],val[p][0]^v);return ;}
	int mid=(l+r)/2;
	down(p);
	reset(p<<1,l,mid);
	reset(p<<1|1,mid+1,r);
	push(p);
}
void modify(int p,int l,int r,int lx,int rx,ll v){
	if(l>=lx&&r<=rx) return upd(p,v);
	int mid=(l+r)/2;
	down(p);
	if(lx<=mid) modify(p<<1,l,mid,lx,rx,v);
	if(rx>mid) modify(p<<1|1,mid+1,r,lx,rx,v);
	push(p);
}
ll query(int p,int l,int r,int lx,int rx){
	ll ans=0;
	if(l>=lx&&r<=rx){
		for(int i=0;i<len[p];i++) ans+=val[p][i]<<i;
		return ans;
	}
	int mid=(l+r)/2;
	down(p);
	if(lx<=mid) ans=query(p<<1,l,mid,lx,rx);
	if(rx>mid) ans+=query(p<<1|1,mid+1,r,lx,rx);
	return ans;
}
signed main(){
	scanf("%d%d",&n,&m);
	auto upd=[&](int x,ll y){
		for(int i=x;i<=n;i+=i&(-i)) c[i]^=y;
	};
	auto sum=[&](int x){
		ll ans=0;
		for(int i=x;i>=1;i-=i&(-i)) ans^=c[i];
		return ans;
	};
	for(int i=1;i<=n;i++)
		scanf("%llu",&a[i]),s[i]=s[i-1]^a[i],upd(i,a[i]);
	build(1,1,n);
	auto insert=[&](ll &x){
		for(int i=63;i>=0;i--) if(x>>i&1){
			if(!b[i]){
				b[i]=x;
				for(int j=i-1;j>=0;j--) if(b[i]>>j&1) b[i]^=b[j];
				for(int j=i+1;j<=63;j++) if(b[j]>>i&1) b[j]^=b[i];
				return 1;
			}
			else x^=b[i];
		}
		return 0;
	};
	auto qryh=[&](ll x){
		for(int i=63;i>=0;i--) x=min(x,x^b[i]);
		return x;
	};
	while(m--){
		scanf("%d",&op);
		if(op==1)
			scanf("%d%llu",&x,&v),
			upd(x,v),modify(1,1,n,x,n,qryh(v));
		if(op==2){
			scanf("%llu",&v);
			if(insert(v)) reset(1,1,n);
		}
		if(op==3){
			scanf("%d%d",&l,&r),v=qryh(sum(l-1));
			modify(1,1,n,l,r,v);
			printf("%lld\n",query(1,1,n,l,r));
			modify(1,1,n,l,r,v);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 5908kb

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:

939900447595
3626355692726
1758813730619
806442991239
321130462705
1699218154542
669763567816
1446781652266
1122900887382
594830426746
1348567121294
577048801927
2274752405990
935865280113
2993407812974
3553201664140
2846461841674
1739088176540
914944228641
241113644850
3227617135361
1860720214960
1...

result:

wrong answer 1st lines differ - expected: '867006634793', found: '939900447595'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 382ms
memory: 58640kb

input:

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

output:

-1261711370135313605
-8273462611451666156
8603244633435200781
694610885162907339
6960626187549258231
6624125181438602206
52748557835967711
5169037328080659288
-7955086376362935848
59308499876315728
-6663568473504659147
2217829093079335741
-7799993970023901493
-8030326982153455695
-696554341756997605...

result:

wrong answer 1st lines differ - expected: '12337138966997790840', found: '-1261711370135313605'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 112ms
memory: 16812kb

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 705th lines differ - expected: '301617306331507', found: '299390159446273'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%