Submission #414735

# Submission time Handle Problem Language Result Execution time Memory
414735 2021-05-31T06:07:14 Z DEQK XORanges (eJOI19_xoranges) C++17
100 / 100
190 ms 10976 KB
#include <bits/stdc++.h>

#define ll long long
#define rs u << 1 | 1
#define ls u << 1 
using namespace std;
const int N = 200200;
int a[N];
int t[N << 2][2];
void build(int u,int l,int r,int i) {
	if(l == r) {
		if((l & 1) == i) {
			t[u][i] = a[l];
		}
		return;
	}
	int m = l + r >> 1;
	build(ls, l, m, i);
	build(rs, m + 1, r, i);
	t[u][i] = t[ls][i] ^ t[rs][i];
}
int get(int ql,int qr,int i,int u,int l,int r) {
	if(ql > r || l > qr) return 0;
	if(ql <= l && r <= qr) return t[u][i];
	int m = l + r >> 1;
	return get(ql,qr,i,ls,l,m) ^ get(ql,qr,i,rs,m + 1,r);
}
void upd(int p,int x,int i,int u,int l,int r) {
	if(l == r) {
		t[u][i] = x;
		return;
	}
	int m = l + r >> 1;
	if(p <= m) upd(p, x, i, ls, l, m);
	else upd(p, x, i, rs, m + 1, r);
	t[u][i] = t[ls][i] ^ t[rs][i];
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, q; cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}	
	for(int i = 0; i < 2; i++) {
		build(1, 1, n, i);
	}	
	while(q--) {
		int tp, l, r; cin >> tp >> l >> r;
		if(tp == 1) {
			upd(l, r, l & 1, 1, 1, n);
		} else {
			if((l & 1) != (r & 1)) {
				cout << "0\n";
				continue;
			}
			cout << get(l, r, l & 1, 1, 1, n) << '\n';
		}
	}
}

Compilation message

xoranges.cpp: In function 'void build(int, int, int, int)':
xoranges.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |  int m = l + r >> 1;
      |          ~~^~~
xoranges.cpp: In function 'int get(int, int, int, int, int, int)':
xoranges.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |  int m = l + r >> 1;
      |          ~~^~~
xoranges.cpp: In function 'void upd(int, int, int, int, int, int)':
xoranges.cpp:33:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |  int m = l + r >> 1;
      |          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 5 ms 620 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 4 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 6392 KB Output is correct
2 Correct 159 ms 6392 KB Output is correct
3 Correct 168 ms 6276 KB Output is correct
4 Correct 139 ms 6356 KB Output is correct
5 Correct 138 ms 6288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 5 ms 620 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 4 ms 576 KB Output is correct
15 Correct 190 ms 6392 KB Output is correct
16 Correct 159 ms 6392 KB Output is correct
17 Correct 168 ms 6276 KB Output is correct
18 Correct 139 ms 6356 KB Output is correct
19 Correct 138 ms 6288 KB Output is correct
20 Correct 156 ms 10904 KB Output is correct
21 Correct 174 ms 10976 KB Output is correct
22 Correct 165 ms 10936 KB Output is correct
23 Correct 150 ms 10824 KB Output is correct
24 Correct 147 ms 10904 KB Output is correct