Submission #1219380

#TimeUsernameProblemLanguageResultExecution timeMemory
1219380Nika533XORanges (eJOI19_xoranges)C++20
100 / 100
208 ms14536 KiB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,t,k;
string s;
const int N=200000;
int a[N+5];
int b[N+5];
int t1[N*4];
int t2[N*4];

void build1(int v, int tl, int tr) {
    if (tl == tr) {
        t1[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build1(v*2, tl, tm);
        build1(v*2+1, tm+1, tr);
        t1[v] = t1[v*2] ^ t1[v*2+1];
    }
}
int xor1(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (l == tl && r == tr) {
        return t1[v];
    }
    int tm = (tl + tr) / 2;
    return xor1(v*2, tl, tm, l, min(r, tm)) ^ xor1(v*2+1, tm+1, tr, max(l, tm+1), r);
}
void update1(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t1[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update1(v*2, tl, tm, pos, new_val);
        else
            update1(v*2+1, tm+1, tr, pos, new_val);
        t1[v] = t1[v*2] ^ t1[v*2+1];
    }
}


void build2(int v, int tl, int tr) {
    if (tl == tr) {
        t2[v] = b[tl];
    } else {
        int tm = (tl + tr) / 2;
        build2(v*2, tl, tm);
        build2(v*2+1, tm+1, tr);
        t2[v] = t2[v*2] ^ t2[v*2+1];
    }
}
int xor2(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (l == tl && r == tr) {
        return t2[v];
    }
    int tm = (tl + tr) / 2;
    return xor2(v*2, tl, tm, l, min(r, tm)) ^ xor2(v*2+1, tm+1, tr, max(l, tm+1), r);
}
void update2(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t2[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update2(v*2, tl, tm, pos, new_val);
        else
            update2(v*2+1, tm+1, tr, pos, new_val);
        t2[v] = t2[v*2] ^ t2[v*2+1];
    }
}
void test_case() {
	cin>>n>>m;
	int arr[n];
	for (int i=0; i<n; i++) {
		cin>>arr[i];
		if (i%2==0) {
			a[i]=arr[i];
		}
		else {
			b[i]=arr[i];
		}
	}
	build1(1,0,n-1);
	build2(1,0,n-1);
	while (m--) {
		int val;
		cin>>val;
		if (val==1) {
			int a,b;
			cin>>a>>b;
			a--;
			if (a%2==0) {
				update1(1,0,n-1,a,b);
			}
			else {
				update2(1,0,n-1,a,b);
			}
		}
		else {
			int a,b;
			cin>>a>>b;
			a--;
			b--;
			if ((b-a+1)%2==0) {
				cout<<0<<endl;
				continue;
			}
			int ans=0;
			if (a%2==0) {
				ans=xor1(1,0,n-1,a,b);
			}
			else{
				ans=xor2(1,0,n-1,a,b);
			}
			cout<<ans<<endl;
		}
	}
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	t=1;
	while (t--) {
		test_case();
	}
}

Compilation message (stderr)

xoranges.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
xoranges.cpp:129:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  129 | 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...