답안 #414731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414731 2021-05-31T06:02:08 Z DEQK XORanges (eJOI19_xoranges) C++17
0 / 100
173 ms 10796 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:12:12: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   12 |   if(l & 1 == i) {
      |          ~~^~~~
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 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 173 ms 10796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -