답안 #569922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569922 2022-05-28T08:34:41 Z jmyszka2007 XORanges (eJOI19_xoranges) C++17
100 / 100
162 ms 7952 KB
#include <bits/stdc++.h>
using namespace std;
constexpr int base = (1 << 18);
int d1[2 * base];
int d2[2 * base];
void upd1(int v, int x) {
	v += base;
	d1[v] = x;
	v >>= 1;
	while(v > 0) {
		d1[v] = d1[2 * v] ^ d1[2 * v + 1];
		v >>= 1;
	}
}
int que1(int l, int r) {
	l += base;
	r += base;
	int ans = 0;
	while(l <= r) {
		if(l & 1) {
			ans ^= d1[l];
		}
		if(!(r & 1)) {
			ans ^= d1[r];
		}
		l++;
		l >>= 1;
		r--;
		r >>= 1;
	}
	return ans;
}
void upd2(int v, int x) {
	v += base;
	d2[v] = x;
	v >>= 1;
	while(v > 0) {
		d2[v] = d2[2 * v] ^ d2[2 * v + 1];
		v >>= 1;
	}
}
int que2(int l, int r) {
	l += base;
	r += base;
	int ans = 0;
	while(l <= r) {
		if(l & 1) {
			ans ^= d2[l];
		}
		if(!(r & 1)) {
			ans ^= d2[r];
		}
		l++;
		l >>= 1;
		r--;
		r >>= 1;
	}
	return ans;
}	 
int main() {
	int n, t;
	scanf("%d%d", &n, &t);
	for(int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		if(i & 1) {
			upd1(i / 2 + 1, x);
		}
		else {
			upd2(i / 2, x);
		}
	}
	while(t--) {
		int tp;
		scanf("%d", &tp);
		if(tp == 1) {
			int v, x;
			scanf("%d%d", &v, &x);
			if(v & 1) {
				upd1(v / 2 + 1, x);
			}
			else {
				upd2(v / 2, x);
			}
		}
		else {
			int l, r;
			scanf("%d%d", &l, &r);
			if((l & 1) != (r & 1)) {
				printf("%d\n", 0);
			}
			else {
				if(l & 1) {
					printf("%d\n", que1(l / 2 + 1, r / 2 + 1));
				}
				else {
					printf("%d\n", que2(l / 2, r / 2));
				}
			}
		}
	}
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d%d", &n, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
xoranges.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d", &tp);
      |   ~~~~~^~~~~~~~~~~
xoranges.cpp:78:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |    scanf("%d%d", &v, &x);
      |    ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:88:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |    scanf("%d%d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 7888 KB Output is correct
2 Correct 134 ms 7884 KB Output is correct
3 Correct 151 ms 7952 KB Output is correct
4 Correct 162 ms 7612 KB Output is correct
5 Correct 121 ms 7612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 448 KB Output is correct
15 Correct 136 ms 7888 KB Output is correct
16 Correct 134 ms 7884 KB Output is correct
17 Correct 151 ms 7952 KB Output is correct
18 Correct 162 ms 7612 KB Output is correct
19 Correct 121 ms 7612 KB Output is correct
20 Correct 129 ms 7640 KB Output is correct
21 Correct 137 ms 7676 KB Output is correct
22 Correct 135 ms 7648 KB Output is correct
23 Correct 154 ms 7556 KB Output is correct
24 Correct 119 ms 7608 KB Output is correct