Submission #787759

#TimeUsernameProblemLanguageResultExecution timeMemory
787759ThylOneXORanges (eJOI19_xoranges)C++14
100 / 100
407 ms11988 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long
const int DEPTH = 18;
const int LEAF = (1<<(DEPTH-1));
const int NB_NODES = (1<<DEPTH);
const int MAXI = 2 * 100000+2;
struct XorTree{
	int vals[NB_NODES];
	void init(){
		for(int i = 0;i<NB_NODES;i++){
			vals[i]=0;
		}
	};
	void update(int pos,int val){
		int node = pos+LEAF;
		int varia = val^vals[node];
		while(node!=1){
			vals[node]^=varia;
			node/=2;
		}
		vals[1]^=varia;
	}
	int _getVal(int gauche,int droite){
		if(droite<gauche){
			return 0;
		}
		if(gauche&1){
			return vals[gauche]^_getVal(gauche+1,droite);
		}
		if(!(droite&1)){
			return vals[droite]^_getVal(gauche,droite-1);
		}
		return _getVal(gauche/2,droite/2);
	}
	int getVal(int gauche,int droite){
		return _getVal(gauche+LEAF,droite+LEAF);
	}
	

};

#include<bits/stdc++.h>
 
using namespace std;
#define int long long
signed main(){
	
	XorTree XT[2];
	XT[0].init();
	XT[1].init();
	int n;cin>>n;
	int q;cin>>q;
	vector<int> nums(n);
	for(int i = 0 ; i < n ; i++){
		cin>>nums[i];
		XT[i%2].update(i/2,nums[i]);
	}
	
	
	
	
	
	for(int _=0;_<q;_++){
		int type;cin>>type;
		if(type==1){
			int pos;cin>>pos;pos--;
			int val;cin>>val;
			XT[pos%2].update(pos/2,val);
		}else{
			int l,r;cin>>l>>r;
			l--;r--;
			if(((r-l)&1)){
				cout<<0<<endl;
			}else{
				if((l/2-1)<0){
					int ans = XT[r%2].getVal(0,r/2);
					cout<<ans<<endl;
				}else{
					int ans = XT[r%2].getVal(0,r/2)^XT[r%2].getVal(0,l/2-1);
					cout<<ans<<endl;
				}
			
				
			}
			
		}
	}
	return 0;
}

/*
 int n;cin>>n;
	int q;cin>>q;
	vector<int> nums(n);
	for(int i = 0 ; i < n ; i++){
		cin>>nums[i];
	}
	int XorPref[n];
	
	int acts[2] = {0,0};
	for(int i = 0;i<n;i++){
		acts[i%2]^=nums[i];
		XorPref[i]=acts[i%2];
	}
	
	for(int _=0;_<q;_++){
		int type;cin>>type;
		if(type==1){
			int pos;cin>>pos;pos--;
			int val;cin>>val;
			nums[pos]=val;
		}else{
			int l,r;cin>>l>>r;
			l--;r--;
			if(((r-l)&1)){
				cout<<0<<endl;
			}else{
				if((l-2)<0){
					int ans = XorPref[r];
					cout<<ans<<endl;
				}else{
					int ans = XorPref[r]^XorPref[l-2];
					cout<<ans<<endl;
				}
			
				
			}
			
		}
	}
	return 0;
 */

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...