Submission #464860

# Submission time Handle Problem Language Result Execution time Memory
464860 2021-08-14T10:31:47 Z Tsovak XORanges (eJOI19_xoranges) C++14
0 / 100
779 ms 14144 KB
// -------------------- Includes -------------------- //
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <array>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <math.h>
#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 <tuple>
#include <utility>
#include <cassert>
#include <assert.h>
#include <climits>
#include <limits.h>
#include <ctime>
#include <time.h>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;

// -------------------- Typedefs -------------------- //

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

// -------------------- Defines -------------------- //

#define pr pair
#define mpr make_pair
#define ff first
#define ss second

#define mset multiset
#define mmap multimap
#define uset unordered_set
#define umap unordered_map
#define umset unordered_multiset
#define ummap unordered_multimap
#define pqueue priority_queue

#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) x.clear()

#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back
#define ft front
#define bk back

#define lb lower_bound
#define ub upper_bound
#define bs binary_search

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

struct node
{
	int ans, xr, sz;
};

const int N = 200005;
int a[N];
int n;

node t[N * 4];

int t1[N * 4], t2[N * 4];

int qry1(int tl, int tr, int l, int r, int pos);

int qry2(int tl, int tr, int l, int r, int pos);

vector<int> v;

node merge(node a, node b, int tl, int tr)
{
	node res;
	res.ans = (a.ans ^ b.ans);
	res.xr = (a.xr ^ b.xr);
	res.sz = a.sz + b.sz;
	int m = (tl + tr) / 2;
	if (a.sz % 2 == 1) {
		if (tr % 2 == 1) {
			res.ans ^= qry1(1, n, m + 1, tr, 1);
		}
		else {
			res.ans ^= qry2(1, n, m + 1, tr, 1);
		}
	}
	if (b.sz % 2 == 1) {
		if (tl % 2 == 1) {
			res.ans ^= qry1(1, n, tl, m, 1);
		}
		else {
			res.ans ^= qry2(1, n, tl, m, 1);
		}
	}
	return res;
}

void bld(int tl, int tr, int pos)
{
	if (tl == tr) {
		t[pos].ans = t[pos].xr = a[tl];
		t[pos].sz = 1;

		if (tl % 2 == 1) {
			t1[pos] = a[tl];
			t2[pos] = 0;
		}
		else {
			t1[pos] = 0;
			t2[pos] = a[tl];
		}
		return;
	}

	int m = (tl + tr) / 2;
	bld(tl, m, pos * 2);
	bld(m + 1, tr, pos * 2 + 1);

	t[pos] = merge(t[pos * 2], t[pos * 2 + 1], tl, tr);
	t1[pos] = (t1[pos * 2] ^ t1[pos * 2 + 1]);
	t2[pos] = (t2[pos * 2] ^ t2[pos * 2 + 1]);
	return;
}

void upd(int tl, int tr, int ind, int x, int pos)
{
	if (tl == tr) {
		t[pos].ans = t[pos].xr = x;

		if (tl % 2 == 1) {
			t1[pos] = a[tl];
			t2[pos] = 0;
		}
		else {
			t1[pos] = 0;
			t2[pos] = a[tl];
		}
		return;
	}

	int m = (tl + tr) / 2;
	if (ind <= m) {
		upd(tl, m, ind, x, pos * 2);
	}
	else {
		upd(m + 1, tr, ind, x, pos * 2 + 1);
	}

	t[pos] = merge(t[pos * 2], t[pos * 2 + 1], tl, tr);
	t1[pos] = (t1[pos * 2] ^ t1[pos * 2 + 1]);
	t2[pos] = (t2[pos * 2] ^ t2[pos * 2 + 1]);
	return;
}

int qry(int tl, int tr, int l, int r, int pos)
{
	if (l > r) {
		return 0;
	}
	if (tl == l && tr == r) {
		return t[pos].ans;
	}

	int m = (tl + tr) / 2;
	return (qry(tl, m, l, min(m, r), pos * 2) ^ qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

int qry1(int tl, int tr, int l, int r, int pos)
{
	if (l > r) {
		return 0;
	}
	if (tl == l && tr == r) {
		return t1[pos];
	}

	int m = (tl + tr) / 2;
	return (qry1(tl, m, l, min(m, r), pos * 2) ^ qry1(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

int qry2(int tl, int tr, int l, int r, int pos)
{
	if (l > r) {
		return 0;
	}
	if (tl == l && tr == r) {
		return t2[pos];
	}

	int m = (tl + tr) / 2;
	return (qry2(tl, m, l, min(m, r), pos * 2) ^ qry2(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

int main()
{
	int i, j;
	int q;
	cin >> n >> q;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	bld(1, n, 1);
	for (i = 1; i <= q; i++) {
		int type;
		cin >> type;
		if (type == 1) {
			int ind, x;
			cin >> ind >> x;
			upd(1, n, ind, x, 1);
		}
		else {
			int l, r;
			cin >> l >> r;
			v.pb(qry(1, n, l, r, 1));
		}
	}
	for (auto i : v) {
		cout << i << endl;
	}
	return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:231:9: warning: unused variable 'j' [-Wunused-variable]
  231 |  int i, j;
      |         ^
# 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 2 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 779 ms 14144 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 -