답안 #642359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
642359 2022-09-19T09:59:57 Z AmirAli_H1 XORanges (eJOI19_xoranges) C++17
100 / 100
157 ms 7976 KB
// In the name of Allah

#include <bits/stdc++.h>
using namespace std;

typedef long long int	ll;
typedef long double	ld;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;

#define all(x)		(x).begin(),(x).end()
#define len(x)		((ll) (x).size())
#define F		first
#define S		second
#define pb		push_back
#define sep             ' '
#define endl            '\n'
#define Mp		make_pair
#define kill(x)		cout << x << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define file_io(x,y)	freopen(x, "r", stdin); freopen(y, "w", stdout);

const int sq = 450;
int sq_xor1[sq], sq_xor2[sq];

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n, q;
	cin >> n >> q;
	
	int a[n];
	int a1[(n + 1) / 2], a2[n / 2];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			a1[i / 2] = a[i];
		}
		else {
			a2[i / 2] = a[i];
		}
	}
	
	for (int i = 0; i < (n + 1) / 2; i++) {
		sq_xor1[i / sq] ^= a1[i];
	}
	
	for (int i = 0; i < n / 2; i++) {
		sq_xor2[i / sq] ^= a2[i];
	}
	
	for (int I = 0; I < q; I++) {
		int x;
		cin >> x;
		if (x == 2) {
			int l, r;
			cin >> l >> r;
			l -= 1; r -= 1;
			int le = r - l + 1;
			if (le % 2 == 0) {
				cout << 0 << endl;
			}
			else {
				int output = 0;
				if (l % 2 == 0) {
					l /= 2; r /= 2;
					if (le <= 3 * sq) {
						for (int i = l; i <= r; i++) {
							output ^= a1[i];
						}
					}
					else {
						int j1 = (l / sq) * sq + sq, j2 = (r / sq) * sq;
						for (int i = l; i < j1; i++) {
							output ^= a1[i];
						}
						for (int i = j1; i < j2; i += sq) {
							output ^= sq_xor1[i / sq];
						}
						for (int i = j2; i <= r; i++) {
							output ^= a1[i];
						}
					}
				}
				else {
					l /= 2; r /= 2;
					if (le <= 3 * sq) {
						for (int i = l; i <= r; i++) {
							output ^= a2[i];
						}
					}
					else {
						int j1 = (l / sq) * sq + sq, j2 = (r / sq) * sq;
						for (int i = l; i < j1; i++) {
							output ^= a2[i];
						}
						for (int i = j1; i < j2; i += sq) {
							output ^= sq_xor2[i / sq];
						}
						for (int i = j2; i <= r; i++) {
							output ^= a2[i];
						}
					}
				}
				cout << output << endl;
			}
		}
		else {
			int i, v;
			cin >> i >> v;
			i -= 1;
			if (i % 2 == 0) {
				i /= 2;
				sq_xor1[i / sq] ^= a1[i];
				a1[i] = v;
				sq_xor1[i / sq] ^= a1[i];
			}
			else {
				i /= 2;
				sq_xor2[i / sq] ^= a2[i];
				a2[i] = v;
				sq_xor2[i / sq] ^= a2[i];
			}
		}
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 5724 KB Output is correct
2 Correct 111 ms 7976 KB Output is correct
3 Correct 131 ms 7880 KB Output is correct
4 Correct 157 ms 7488 KB Output is correct
5 Correct 134 ms 7492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 118 ms 5724 KB Output is correct
16 Correct 111 ms 7976 KB Output is correct
17 Correct 131 ms 7880 KB Output is correct
18 Correct 157 ms 7488 KB Output is correct
19 Correct 134 ms 7492 KB Output is correct
20 Correct 95 ms 7556 KB Output is correct
21 Correct 94 ms 7612 KB Output is correct
22 Correct 97 ms 7608 KB Output is correct
23 Correct 156 ms 7484 KB Output is correct
24 Correct 130 ms 7496 KB Output is correct