Submission #731072

# Submission time Handle Problem Language Result Execution time Memory
731072 2023-04-26T22:33:25 Z Mher777 XORanges (eJOI19_xoranges) C++17
100 / 100
138 ms 14492 KB
//////////////////////////////// Mher777
/* -------------------- Includes -------------------- */
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
using namespace std;

/* -------------------- Typedefs -------------------- */

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef float fl;
typedef double db;
typedef long double ld;

/* -------------------- Usings -------------------- */

using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* -------------------- Defines -------------------- */

#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) (x).begin(), (x).end()

/* -------------------- Constants -------------------- */

const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);

/* -------------------- Functions -------------------- */

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	return;
}

void precision(int x) {
	cout.setf(ios::fixed | ios::showpoint);
	cout.precision(x);
	return;
}

ll gcd(ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll range_sum(ll a, ll b) {
	ll dif = a - 1, cnt = b - a + 1;
	ll ans = ((b - a + 1) * (b - a + 2)) / 2;
	ans += ((b - a + 1) * dif);
	return ans;
}

string to2(ll a)
{
	string s = "";
	for (ll i = a; i > 0; ) {
		ll k = i % 2;
		i /= 2;
		char c = k + 48;
		s += c;
	}
	if (a == 0) {
		s = "0";
	}
	reverse(all(s));
	return s;
}

bool isPrime(ll a) {
	if (a == 1) {
		return false;
	}
	for (ll i = 2; i * i <= a; i++) {
		if (a % i == 0) {
			return false;
		}
	}
	return true;
}

int dig_sum(ll a) {
	int sum = 0;
	while (a) {
		sum += int(a % 10);
		a /= 10;
	}
	return sum;
}

ll binpow(ll a, int b) {
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
		}
		b >>= 1;
		a *= a;
	}
	return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
			ans %= mod;
		}
		b >>= 1;
		a *= a;
		a %= mod;
	}
	return ans;
}

ll factorial(int a) {
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
	}
	return ans;
}

ll factorial_by_mod(int a, ll mod) {
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
		ans %= mod;
	}
	return ans;
}

/* -------------------- Solution -------------------- */

const int N = 200005;
ll a[N], a1[N], a2[N], t1[N * 4], t2[N * 4];
int par1[N], par2[N];

void bld(int l, int r, int pos, int type) {
	int mid = (l + r) / 2;
	if (l == r) {
		if (type == 1) {
			t1[pos] = a1[l];
			par1[l] = pos;
		}
		else {
			t2[pos] = a2[l];
			par2[l] = pos;
		}
	}
	else {
		bld(l, mid, 2 * pos, type);
		bld(mid + 1, r, 2 * pos + 1, type);
		if (type == 1) {
			t1[pos] = t1[2 * pos] ^ t1[2 * pos + 1];
		}
		else {
			t2[pos] = t2[2 * pos] ^ t2[2 * pos + 1];
		}
	}
}

ll qry(int l, int r, int tl, int tr, int pos, int type) {
	int mid = (tl + tr) / 2;
	if (l == tl && r == tr) {
		return (type == 1 ? t1[pos] : t2[pos]);
	}
	if (r <= mid) {
		return qry(l, r, tl, mid, 2 * pos, type);
	}
	if (l > mid) {
		return qry(l, r, mid + 1, tr, 2 * pos + 1, type);
	}
	return qry(l, mid, tl, mid, 2 * pos, type) ^
		qry(mid + 1, r, mid + 1, tr, 2 * pos + 1, type);
}

void upd(int ind, ll val, int type) {
	int p;
	if (type == 1) {
		p = par1[ind];
		t1[p] = val;
		a1[ind] = val;
	}
	else {
		p = par2[ind];
		t2[p] = val;
		a2[ind] = val;
	}
	p /= 2;
	while (p) {
		if (type == 1) {
			t1[p] = t1[2 * p] ^ t1[2 * p + 1];
		}
		else {
			t2[p] = t2[2 * p] ^ t2[2 * p + 1];
		}
		p /= 2;
	}
}

void slv() {
	int n, q, n1, n2;
	cin >> n >> q;
	// 1 -> kent
	// 2 -> zuyg
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i % 2 == 1) {
			a1[(i + 1) / 2] = a[i];
		}
		else {
			a2[i / 2] = a[i];
		}
	}
	if (n % 2 == 0) {
		n1 = n / 2, n2 = n / 2;
		bld(1, n / 2, 1, 1);
		bld(1, n / 2, 1, 2);
	}
	else {
		n1 = (n + 1) / 2, n2 = n / 2;
		bld(1, (n + 1) / 2, 1, 1);
		if (n != 1) {
			bld(1, n / 2, 1, 2);
		}
	}
	while (q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int ind;
			ll val;
			cin >> ind >> val;
			int tp = (ind % 2 == 1 ? 1 : 2);
			if (ind % 2 == 1) {
				ind = ind / 2 + 1;
			}
			else {
				ind /= 2;
			}
			upd(ind, val, tp);
		}
		else {
			int l, r;
			cin >> l >> r;
			if ((r - l + 1) % 2 == 0) {
				cout << 0 << '\n';
			}
			else {
				if (l % 2 == 0) {
					cout << qry(l / 2, r / 2, 1, n2, 1, 2) << '\n';
				}
				else {
					if (r % 2 == 1) {
						r /= 2;
						r++;
					}
					else {
						r /= 2;
					}
					cout << qry(l / 2 + 1, r, 1, n1, 1, 1) << '\n';
				}
			}
		}
	}
}

void cs() {
	int tstc = 1;
	//cin >> tstc;
	while (tstc--) {
		slv();
	}
}

void precalc() {
	return;
}

int main() {
	fastio();
	//precalc();
	//precision(1);
	cs();
	return 0;
}

Compilation message

xoranges.cpp: In function 'll range_sum(ll, ll)':
xoranges.cpp:93:18: warning: unused variable 'cnt' [-Wunused-variable]
   93 |  ll dif = a - 1, cnt = b - a + 1;
      |                  ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 336 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 14336 KB Output is correct
2 Correct 116 ms 14284 KB Output is correct
3 Correct 138 ms 14492 KB Output is correct
4 Correct 117 ms 14044 KB Output is correct
5 Correct 110 ms 14052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 336 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 138 ms 14336 KB Output is correct
16 Correct 116 ms 14284 KB Output is correct
17 Correct 138 ms 14492 KB Output is correct
18 Correct 117 ms 14044 KB Output is correct
19 Correct 110 ms 14052 KB Output is correct
20 Correct 123 ms 14144 KB Output is correct
21 Correct 126 ms 14048 KB Output is correct
22 Correct 113 ms 14100 KB Output is correct
23 Correct 106 ms 14032 KB Output is correct
24 Correct 111 ms 13968 KB Output is correct