답안 #414733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414733 2021-05-31T06:04:57 Z DEQK XORanges (eJOI19_xoranges) C++17
38 / 100
176 ms 11156 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, i, 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;
      |          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 6348 KB Output is correct
2 Correct 176 ms 11152 KB Output is correct
3 Correct 171 ms 11156 KB Output is correct
4 Correct 145 ms 10872 KB Output is correct
5 Correct 146 ms 10872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -