Submission #255991

# Submission time Handle Problem Language Result Execution time Memory
255991 2020-08-02T07:36:48 Z tomsyd XORanges (eJOI19_xoranges) C++17
100 / 100
190 ms 16416 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5+1;
vector<int> a(N);

void build(int idx, int l, int r, vector<int>& segt, int rest){
	if (l == r){
		if (l%2 == rest) segt[idx] = a[l];
		return;
	}
	int mid = (l+r)>>1;
	build(2*idx,l,mid,segt,rest);
	build(2*idx+1,mid+1,r,segt,rest);
	segt[idx] = segt[2*idx]^segt[2*idx+1];
}

void modify(int idx, int l, int r, int pos, int val, vector<int>& segt){
	if (r < pos or l > pos) return;
	if (l == r){
		segt[idx] = val;
		return;
	}
	int mid = (l+r)>>1;
	modify(2*idx,l,mid,pos,val,segt);
	modify(2*idx+1,mid+1,r,pos,val,segt);
	segt[idx] = segt[2*idx]^segt[2*idx+1];
}

int query(int idx, int l, int r, int L, int R, vector<int>& segt){
	if (r < L or l > R) return 0;
	if (l >= L and r <= R) return segt[idx];
	int mid = (l+r)>>1;
	return query(2*idx,l,mid,L,R,segt)^query(2*idx+1,mid+1,r,L,R,segt);
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,q;
	cin >> n >> q;
	vector<int> odd(4*N+5), even(4*N+5);
	for (int i=0; i<n; ++i){
		cin >> a[i];
	}
	build(1,0,n-1,even,0);
	build(1,0,n-1,odd,1);
	for (int i=0; i<q; ++i){
		int type;
		cin >> type;
		if (type == 1){
			int pos, val;
			cin >> pos >> val;
			pos--;
			if (pos%2 == 0) modify(1,0,n-1,pos,val,even);
			else modify(1,0,n-1,pos,val,odd);
		}
		else{
			int l,r;
			cin >> l >> r;
			l--; r--;
			int ans = 0;
			if ((r-l+1)%2 == 0){
				cout << 0 << '\n';
				continue;
				if (l%2 == 0) ans = query(1,0,n-1,l,r,odd);
				else ans = query(1,0,n-1,l,r,even);
			}
			else{
				if (l%2 == 0) ans = query(1,0,n-1,l,r,even);
				else ans = query(1,0,n-1,l,r,odd);
			}
			cout << ans << '\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14464 KB Output is correct
2 Correct 8 ms 14464 KB Output is correct
3 Correct 8 ms 14464 KB Output is correct
4 Correct 9 ms 14428 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 8 ms 14464 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14464 KB Output is correct
2 Correct 8 ms 14464 KB Output is correct
3 Correct 8 ms 14464 KB Output is correct
4 Correct 9 ms 14428 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 8 ms 14464 KB Output is correct
9 Correct 9 ms 14464 KB Output is correct
10 Correct 8 ms 14464 KB Output is correct
11 Correct 11 ms 14592 KB Output is correct
12 Correct 11 ms 14592 KB Output is correct
13 Correct 12 ms 14592 KB Output is correct
14 Correct 11 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 15744 KB Output is correct
2 Correct 165 ms 16376 KB Output is correct
3 Correct 190 ms 16416 KB Output is correct
4 Correct 153 ms 16376 KB Output is correct
5 Correct 148 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14464 KB Output is correct
2 Correct 8 ms 14464 KB Output is correct
3 Correct 8 ms 14464 KB Output is correct
4 Correct 9 ms 14428 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 8 ms 14464 KB Output is correct
9 Correct 9 ms 14464 KB Output is correct
10 Correct 8 ms 14464 KB Output is correct
11 Correct 11 ms 14592 KB Output is correct
12 Correct 11 ms 14592 KB Output is correct
13 Correct 12 ms 14592 KB Output is correct
14 Correct 11 ms 14592 KB Output is correct
15 Correct 182 ms 15744 KB Output is correct
16 Correct 165 ms 16376 KB Output is correct
17 Correct 190 ms 16416 KB Output is correct
18 Correct 153 ms 16376 KB Output is correct
19 Correct 148 ms 16376 KB Output is correct
20 Correct 175 ms 15864 KB Output is correct
21 Correct 183 ms 15864 KB Output is correct
22 Correct 177 ms 15864 KB Output is correct
23 Correct 143 ms 16380 KB Output is correct
24 Correct 158 ms 16376 KB Output is correct