Submission #997384

#TimeUsernameProblemLanguageResultExecution timeMemory
997384vjudge1XORanges (eJOI19_xoranges)C++17
100 / 100
88 ms16728 KiB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define F first
#define S second
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;
const int N = 500001;

using namespace std;
using namespace __gnu_pbds;

ll tt, n, m, k, a, b, c, d, e, f[N], p[N], l, r, t[N * 4][2];

void build (ll tl = 1, ll tr = n, ll v = 1){
	if (tl == tr){
		if (tl % 2){
			t[v][1] = p[tl];
			t[v][0] = 0;
		}
		else{
			t[v][0] = p[tl];
			t[v][1] = 0;
		}
		return;
	}
	ll tm = (tl + tr) / 2;
	build (tl, tm, v + v);
	build (tm + 1, tr, v + v + 1);
	t[v][1] = (t[v + v][1] ^ t[v + v + 1][1]);
	t[v][0] = (t[v + v][0] ^ t[v + v + 1][0]);
}

void upd (ll idx, ll val, ll tl = 1, ll tr = n, ll v = 1){
	if (tr < idx || tl > idx){
		return;
	}
	if (tl == tr && tl == idx){
		if (tl % 2){
			t[v][1] = val;
			t[v][0] = 0;
		}
		else{
			t[v][0] = val;
			t[v][1] = 0;
		}
		return;
	}
	ll tm = (tl + tr) / 2;
	upd (idx, val, tl, tm, v + v);
	upd (idx, val, tm + 1, tr, v + v + 1);
	t[v][1] = (t[v + v][1] ^ t[v + v + 1][1]);
	t[v][0] = (t[v + v][0] ^ t[v + v + 1][0]);
}

ll get (ll l, ll r, ll tp, ll tl = 1, ll tr = n, ll v = 1){
	if (l <= tl && tr <= r){
		return t[v][tp];
	}
	if (tr < l || tl > r){
		return 0;
	}
	ll tm = (tl + tr) / 2;
	return (get (l, r, tp, tl, tm, v + v) ^ get (l, r, tp, tm + 1, tr, v + v + 1));
}

signed main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	build ();
	while (m--){
		ll tp;
		cin >> tp;
		if (tp == 1){
			cin >> a >> b;
			upd (a, b);
		}
		else{
			cin >> a >> b;
			if ((b - a + 1) % 2){
				cout << get (a, b, a % 2) << '\n';
			}
			else{
				cout << "0\n";
			}
		}
	}
}
#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...