Submission #785825

#TimeUsernameProblemLanguageResultExecution timeMemory
785825BulaXORanges (eJOI19_xoranges)C++17
100 / 100
555 ms51716 KiB
#include <bits/stdc++.h>
using namespace std;
 	
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define pi pair<int,int>
#define pii pair< pair<int,int> , pair<int,int> >  
#define int ll
const ll mod=1e9+7,N=2e5+1;
vector<int> a(N);
vector< vector<int> > t(4 * N, vector<int> (2));
 
 
int combine(int a,int b){
	return a^b;
}
 
//
//void build(int v, int tl, int tr) {
//    if (tl == tr) {
//        t[v] = a[tl];
//    } else {
//        int tm = (tl + tr) / 2;
//        build(v*2, tl, tm);
//        build(v*2+1, tm+1, tr);
//        t[v]=combine(t[v*2],t[v*2+1]);
//    }
//}
 
int get(int v, int tl, int tr, int l, int r, int p) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v][p];
    }
    int tm = (tl + tr) / 2;
    return combine(get(v*2, tl, tm, l, min(r, tm), p),get(v*2+1, tm+1, tr, max(l, tm+1), r, p));
}
 
void up(int v, int tl, int tr, int pos, int new_val, int p) {
    if (tl == tr) {
        t[v][p] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            up(v*2, tl, tm, pos, new_val, p);
        else
            up(v*2+1, tm+1, tr, pos, new_val, p);
		t[v][p] = combine(t[v*2][p],t[v*2+1][p]);
    }
}

 
main(){
 
    int tt=1;//cin>>tt;
    while(tt--){
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		int x;
    		cin>>x;
    		up(1, 1, n, i, x, i % 2);
		}
		
		for(int i=1;i<=m;i++){
			int x;
			cin>>x;
			if(x == 1){
				int pos,k;
				cin >> pos >> k;
				up(1, 1, n, pos, k, pos % 2);
			}else{
				int l,r;
				cin >> l >> r;
				if((r-l+1)%2==0) cout << 0 << endl;
				else{
					cout << get(1, 1, n, l, r, l % 2) << endl;
				}
			}
		}
    }
}

Compilation message (stderr)

xoranges.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main(){
      | ^~~~
#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...