답안 #966219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966219 2024-04-19T14:25:04 Z vjudge1 XORanges (eJOI19_xoranges) C++17
100 / 100
112 ms 16904 KB
#include<bits/stdc++.h>
#define INF 1e9
#define fi first
#define se second
#define FOR(i, k, n) for(int i = k; i <= n; i++)
#define FOR1(i, k, n) for(int i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "DANCE.inp"
#define output "DANCE.out"
#define rf 	freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
pll T[maxn * 4];
int a[maxn];
void build(int id, int l, int r)
{
	if(l == r)
	{
		if(l % 2)
			T[id].fi = a[l], T[id].se = 0;
		else
			T[id].se = a[l], T[id].fi = 0;
		return;
	}
	int mid = (l + r) / 2;
	build(id * 2, l, mid);
	build(id * 2 + 1, mid + 1, r);
	T[id].fi = T[id * 2].fi ^ T[id * 2 + 1].fi;
	T[id].se = T[id * 2].se ^ T[id * 2 + 1].se;
}
void update(int id, int l, int r, int pos, int val)
{
	if(l == r)
	{
		if(pos % 2)
			T[id].fi = val;
		else
			T[id].se = val;
		return;
	}
	int mid = (l + r) / 2;
	if(pos <= mid)
		update(id * 2, l, mid, pos, val);
	else
		update(id * 2 + 1, mid + 1, r, pos, val);
	T[id].fi = T[id * 2].fi ^ T[id * 2 + 1].fi;
	T[id].se = T[id * 2].se ^ T[id * 2 + 1].se;
}
ll get1(int id, int l, int r, int u, int v)
{
	if(l > v || r < u)
		return 0;
	if(l >= u && r <= v)
		return T[id].fi;
	int mid = (l + r) / 2;
	return get1(id * 2, l, mid, u, v) ^ get1(id * 2 + 1, mid + 1, r, u, v);
}
ll get2(int id, int l, int r, int u, int v)
{
	if(l > v || r < u)
		return 0;
	if(l >= u && r <= v)
		return T[id].se;
	int mid = (l + r) / 2;
	return get2(id * 2, l, mid, u, v) ^ get2(id * 2 + 1, mid + 1, r, u, v);
}
int main()
{
	fastio;
	int n, q;
	cin >> n >> q;
	FOR(i, 1, n)
		cin >> a[i];
	build(1, 1, n);
	while(q--)
	{
		int op;
		cin >> op;
		if(op == 1)
		{
			int pos, val;
			cin >> pos >> val;
			update(1, 1, n, pos, val);
		}
		else
		{
			int l, r;
			cin >> l >> r;
			if((r - l + 1) % 2 == 0)
			{
				cout << "0\n";
				continue;
			}
			if(l % 2)
				cout << get1(1, 1, n, l, r) << "\n";
			else
				cout << get2(1, 1, n, l, r) << '\n';
		}
	}
	re;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 2 ms 2528 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 14676 KB Output is correct
2 Correct 92 ms 16720 KB Output is correct
3 Correct 91 ms 16904 KB Output is correct
4 Correct 83 ms 16464 KB Output is correct
5 Correct 87 ms 16512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 2 ms 2528 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 96 ms 14676 KB Output is correct
16 Correct 92 ms 16720 KB Output is correct
17 Correct 91 ms 16904 KB Output is correct
18 Correct 83 ms 16464 KB Output is correct
19 Correct 87 ms 16512 KB Output is correct
20 Correct 112 ms 16436 KB Output is correct
21 Correct 102 ms 16428 KB Output is correct
22 Correct 112 ms 16584 KB Output is correct
23 Correct 88 ms 16532 KB Output is correct
24 Correct 84 ms 16512 KB Output is correct