Submission #198506

# Submission time Handle Problem Language Result Execution time Memory
198506 2020-01-26T12:22:44 Z ZwariowanyMarcin Klasika (COCI20_klasika) C++14
110 / 110
3657 ms 422776 KB
#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

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 time Memory Grader output
1 Correct 9 ms 5240 KB Output is correct
2 Correct 9 ms 5240 KB Output is correct
3 Correct 9 ms 5500 KB Output is correct
4 Correct 9 ms 5500 KB Output is correct
5 Correct 9 ms 5112 KB Output is correct
6 Correct 9 ms 5240 KB Output is correct
7 Correct 9 ms 5496 KB Output is correct
8 Correct 9 ms 5624 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 9 ms 5368 KB Output is correct
11 Correct 9 ms 5496 KB Output is correct
12 Correct 9 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5240 KB Output is correct
2 Correct 9 ms 5240 KB Output is correct
3 Correct 9 ms 5500 KB Output is correct
4 Correct 9 ms 5500 KB Output is correct
5 Correct 9 ms 5112 KB Output is correct
6 Correct 9 ms 5240 KB Output is correct
7 Correct 9 ms 5496 KB Output is correct
8 Correct 9 ms 5624 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 9 ms 5368 KB Output is correct
11 Correct 9 ms 5496 KB Output is correct
12 Correct 9 ms 5496 KB Output is correct
13 Correct 12 ms 6396 KB Output is correct
14 Correct 14 ms 7672 KB Output is correct
15 Correct 16 ms 8952 KB Output is correct
16 Correct 17 ms 10104 KB Output is correct
17 Correct 12 ms 6392 KB Output is correct
18 Correct 14 ms 7544 KB Output is correct
19 Correct 16 ms 8820 KB Output is correct
20 Correct 17 ms 9976 KB Output is correct
21 Correct 12 ms 6396 KB Output is correct
22 Correct 15 ms 7672 KB Output is correct
23 Correct 16 ms 8824 KB Output is correct
24 Correct 17 ms 9980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 972 ms 118440 KB Output is correct
2 Correct 1794 ms 221272 KB Output is correct
3 Correct 2368 ms 319584 KB Output is correct
4 Correct 3135 ms 418688 KB Output is correct
5 Correct 1050 ms 116728 KB Output is correct
6 Correct 2012 ms 217976 KB Output is correct
7 Correct 2355 ms 315016 KB Output is correct
8 Correct 3010 ms 411792 KB Output is correct
9 Correct 1000 ms 119288 KB Output is correct
10 Correct 1714 ms 221896 KB Output is correct
11 Correct 2395 ms 320572 KB Output is correct
12 Correct 3051 ms 417256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5240 KB Output is correct
2 Correct 9 ms 5240 KB Output is correct
3 Correct 9 ms 5500 KB Output is correct
4 Correct 9 ms 5500 KB Output is correct
5 Correct 9 ms 5112 KB Output is correct
6 Correct 9 ms 5240 KB Output is correct
7 Correct 9 ms 5496 KB Output is correct
8 Correct 9 ms 5624 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 9 ms 5368 KB Output is correct
11 Correct 9 ms 5496 KB Output is correct
12 Correct 9 ms 5496 KB Output is correct
13 Correct 12 ms 6396 KB Output is correct
14 Correct 14 ms 7672 KB Output is correct
15 Correct 16 ms 8952 KB Output is correct
16 Correct 17 ms 10104 KB Output is correct
17 Correct 12 ms 6392 KB Output is correct
18 Correct 14 ms 7544 KB Output is correct
19 Correct 16 ms 8820 KB Output is correct
20 Correct 17 ms 9976 KB Output is correct
21 Correct 12 ms 6396 KB Output is correct
22 Correct 15 ms 7672 KB Output is correct
23 Correct 16 ms 8824 KB Output is correct
24 Correct 17 ms 9980 KB Output is correct
25 Correct 972 ms 118440 KB Output is correct
26 Correct 1794 ms 221272 KB Output is correct
27 Correct 2368 ms 319584 KB Output is correct
28 Correct 3135 ms 418688 KB Output is correct
29 Correct 1050 ms 116728 KB Output is correct
30 Correct 2012 ms 217976 KB Output is correct
31 Correct 2355 ms 315016 KB Output is correct
32 Correct 3010 ms 411792 KB Output is correct
33 Correct 1000 ms 119288 KB Output is correct
34 Correct 1714 ms 221896 KB Output is correct
35 Correct 2395 ms 320572 KB Output is correct
36 Correct 3051 ms 417256 KB Output is correct
37 Correct 1930 ms 122332 KB Output is correct
38 Correct 2566 ms 224464 KB Output is correct
39 Correct 3104 ms 325612 KB Output is correct
40 Correct 3504 ms 422776 KB Output is correct
41 Correct 1893 ms 120056 KB Output is correct
42 Correct 2543 ms 221008 KB Output is correct
43 Correct 2969 ms 318624 KB Output is correct
44 Correct 3470 ms 414844 KB Output is correct
45 Correct 2145 ms 119652 KB Output is correct
46 Correct 3001 ms 221928 KB Output is correct
47 Correct 3523 ms 319292 KB Output is correct
48 Correct 3657 ms 417572 KB Output is correct