Submission #463566

# Submission time Handle Problem Language Result Execution time Memory
463566 2021-08-11T10:14:46 Z Elias XORanges (eJOI19_xoranges) C++17
0 / 100
310 ms 30564 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

struct XORange
{
	int size;	 // the size of the range
	int xorEven; // the xor of all even elements in range
	int xorOdd;	 // the xor of all odd elemements in range

	XORange operator+(XORange other)
	{
		if (size % 2) // if size of current range is odd, the even / odd of other range gets swapped
			swap(other.xorEven, other.xorOdd);
		return {size + other.size, other.xorEven ^ xorEven, other.xorOdd ^ xorOdd};
	}
};
const XORange neutral{0, 0, 0};

vector<XORange> a;
vector<XORange> b;

XORange segInit(int l, int r, int i)
{
	if (l + 1 == r)
		return b[i] = a[l];
	int m = (l + r) / 2;
	return b[i] = segInit(l, m, i * 2 + 1) + segInit(m, r, i * 2 + 2);
}

XORange segGet(int l, int r, int i, int qL, int qR)
{
	if (l >= qR || r <= qL) // out of range
		return neutral;
	if (l >= qL && r <= qR) // completely within range
		return b[i];
	int m = (l + r) / 2;
	return segGet(l, m, i * 2 + 1, qL, qR) + segGet(m, r, i * 2 + 2, qL, qR);
}

XORange segSet(int l, int r, int i, int k, XORange x)
{
	if (k < l || k >= r)
		return b[i];
	if (l + 1 == r)
		return b[i] = a[k] = x;
	int m = (l + r) / 2;
	return b[i] = segSet(l, m, i * 2 + 1, k, x) + segSet(m, r, i * 2 + 2, k, x);
}

signed main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, q;
	cin >> n >> q;

	a = vector<XORange>(n);
	b = vector<XORange>(n * 4);

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[i] = {1, x, 0};
	}

	segInit(0, n, 0);

	while (q--)
	{
		int t;
		cin >> t;
		if (t == 1)
		{ // update
			int k, x;
			cin >> k >> x;
			k--; // stupid 1 based indexing
			segSet(0, n, 0, k, {1, x, 0});
		}
		else
		{
			int l, r;
			cin >> l >> r;
			l--; // stupid 1 based indexing
			auto range = segGet(0, n, 0, l, r);
			cout << range.xorEven << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 30564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -