Submission #198506

#TimeUsernameProblemLanguageResultExecution timeMemory
198506ZwariowanyMarcinKlasika (COCI20_klasika)C++14
110 / 110
3657 ms422776 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;		

const int nax = 200100;
const int pod = (1 << 18);
const int N = 6000100;

int q;
int t[nax];
int a[nax];
int b[nax];
int e[nax];

char s[10];

vector <int> v[nax];
int path[nax];

int tim;
int in[nax];
int out[nax];

void dfs(int u) {
	in[u] = tim++;
	for (auto it : v[u])
		dfs(it);
	out[u] = tim;
}

struct nod {
	nod *t[2];
	set <int> s;
	nod () {
		t[0] = 0;
		t[1] = 0;
	}
};

void add(nod *u, int nr, int x, int bit = 29) {
	if (bit == -1) return;
	int b = ((x >> bit) & 1);
	if (u->t[b] == 0)
		u->t[b] = new nod();
	u->t[b]->s.insert(nr);
	add(u->t[b], nr, x, bit - 1);
}

int query(nod *u, int l, int r, int x, int bit = 29) {
	if (bit == -1 || !u) return 0;
	int b = !((x >> bit) & 1);
	if (u->t[b] && u->t[b]->s.lower_bound(l) != u->t[b]->s.end() && *u->t[b]->s.lower_bound(l) <= r) {
		return (1 << bit) + query(u->t[b], l, r, x, bit - 1);
	}
	return query(u->t[!b], l, r, x, bit - 1);
}

int main() {
	scanf ("%d", &q);
	int node = 2;
	for (int i = 1; i <= q; ++i) {
		scanf ("%s%d%d", s, a + i, b + i);
		t[i] = (s[0] == 'A');
		if (t[i]) {
			e[i] = node;
			path[node] = (path[a[i]] ^ b[i]);
			v[a[i]].pb(node++);
		}
	}
	dfs(1);
	
	nod root = nod();
	
	add(&root, in[1], 0);
	
	for (int i = 1; i <= q; ++i) {
		if (t[i] == 1) add(&root, in[e[i]], path[e[i]]);
		else printf ("%d\n", query(&root, in[b[i]], out[b[i]] - 1, path[a[i]]));
	} 
		
	return 0;
}

Compilation message (stderr)

klasika.cpp: In function 'int main()':
klasika.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &q);
  ~~~~~~^~~~~~~~~~
klasika.cpp:73:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s%d%d", s, a + i, b + i);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...