# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
500972 |
2022-01-01T19:16:04 Z |
someone |
Klasika (COCI20_klasika) |
C++14 |
|
666 ms |
245768 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 42, INF = 1e18 + 42, MOD = 1e9 + 7;
struct Query {
int a, t;
};
struct Node {
int id[2], mini;
};
struct Trie {
int sz = 0;
vector<Query> q;
vector<Node> node;
Trie() {
node.push_back({{-1, -1}, INF});
}
void insert(int val, int t) {
int a = 0;
q.push_back({val, t});
for(int i = 29; i > -1; i--) {
int b = min((val & (1 << i)), 1ll);
if(node[a].id[b] == -1) {
node[a].id[b] = ++sz;
node.push_back({{-1, -1}, INF});
}
a = node[a].id[b];
node[a].mini = min(node[a].mini, t);
}
}
int getMax(int val, int t) {
int ans = 0, a = 0;
for(int i = 29; i > -1; i--) {
ans <<= 1;
int b = min((val & (1 << i)), 1ll);
if(node[a].id[1 - b] != -1 && node[node[a].id[1 - b]].mini < t) {
ans++;
a = node[a].id[1 - b];
} else
a = node[a].id[b];
}
return ans;
}
};
vector<Query> q[N];
vector<int> adj[N];
int n, XOR[N], temps[N], ans[N];
Trie DFS(int i) {
Trie act;
act.insert(XOR[i], temps[i]);
for(int j : adj[i]) {
Trie child = DFS(j);
if(child.q.size() > act.q.size())
swap(child, act);
for(Query req : child.q)
act.insert(req.a, req.t);
}
for(Query req : q[i])
ans[req.t] = act.getMax(XOR[req.a], req.t);
return act;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
int nb = 1;
for(int i = 0; i < n; i++)
ans[i] = -1;
for(int i = 0; i < n; i++) {
string str;
int a, b;
cin >> str >> a >> b;
if(str[0] == 'A') {
a--;
temps[nb] = i;
adj[a].push_back(nb);
XOR[nb] = XOR[a] ^ b;
nb++;
} else {
q[b-1].push_back({a-1, i});
}
}
DFS(0);
for(int i = 0; i < n; i++)
if(ans[i] != -1)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9844 KB |
Output is correct |
2 |
Correct |
5 ms |
9852 KB |
Output is correct |
3 |
Correct |
5 ms |
9976 KB |
Output is correct |
4 |
Correct |
5 ms |
9972 KB |
Output is correct |
5 |
Correct |
5 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9844 KB |
Output is correct |
7 |
Correct |
7 ms |
9824 KB |
Output is correct |
8 |
Correct |
6 ms |
9844 KB |
Output is correct |
9 |
Correct |
5 ms |
9852 KB |
Output is correct |
10 |
Correct |
5 ms |
9932 KB |
Output is correct |
11 |
Correct |
7 ms |
9932 KB |
Output is correct |
12 |
Correct |
5 ms |
9880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9844 KB |
Output is correct |
2 |
Correct |
5 ms |
9852 KB |
Output is correct |
3 |
Correct |
5 ms |
9976 KB |
Output is correct |
4 |
Correct |
5 ms |
9972 KB |
Output is correct |
5 |
Correct |
5 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9844 KB |
Output is correct |
7 |
Correct |
7 ms |
9824 KB |
Output is correct |
8 |
Correct |
6 ms |
9844 KB |
Output is correct |
9 |
Correct |
5 ms |
9852 KB |
Output is correct |
10 |
Correct |
5 ms |
9932 KB |
Output is correct |
11 |
Correct |
7 ms |
9932 KB |
Output is correct |
12 |
Correct |
5 ms |
9880 KB |
Output is correct |
13 |
Correct |
6 ms |
10684 KB |
Output is correct |
14 |
Correct |
7 ms |
11592 KB |
Output is correct |
15 |
Correct |
9 ms |
12100 KB |
Output is correct |
16 |
Correct |
8 ms |
13256 KB |
Output is correct |
17 |
Correct |
7 ms |
10408 KB |
Output is correct |
18 |
Correct |
8 ms |
10832 KB |
Output is correct |
19 |
Correct |
9 ms |
11108 KB |
Output is correct |
20 |
Correct |
11 ms |
11128 KB |
Output is correct |
21 |
Correct |
9 ms |
10428 KB |
Output is correct |
22 |
Correct |
8 ms |
11032 KB |
Output is correct |
23 |
Correct |
10 ms |
11464 KB |
Output is correct |
24 |
Correct |
12 ms |
11648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
89164 KB |
Output is correct |
2 |
Correct |
280 ms |
135792 KB |
Output is correct |
3 |
Correct |
337 ms |
192020 KB |
Output is correct |
4 |
Correct |
388 ms |
245680 KB |
Output is correct |
5 |
Correct |
250 ms |
44136 KB |
Output is correct |
6 |
Correct |
394 ms |
96040 KB |
Output is correct |
7 |
Correct |
514 ms |
88500 KB |
Output is correct |
8 |
Correct |
624 ms |
143264 KB |
Output is correct |
9 |
Correct |
224 ms |
68096 KB |
Output is correct |
10 |
Correct |
308 ms |
114676 KB |
Output is correct |
11 |
Correct |
354 ms |
139412 KB |
Output is correct |
12 |
Correct |
433 ms |
210656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9844 KB |
Output is correct |
2 |
Correct |
5 ms |
9852 KB |
Output is correct |
3 |
Correct |
5 ms |
9976 KB |
Output is correct |
4 |
Correct |
5 ms |
9972 KB |
Output is correct |
5 |
Correct |
5 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9844 KB |
Output is correct |
7 |
Correct |
7 ms |
9824 KB |
Output is correct |
8 |
Correct |
6 ms |
9844 KB |
Output is correct |
9 |
Correct |
5 ms |
9852 KB |
Output is correct |
10 |
Correct |
5 ms |
9932 KB |
Output is correct |
11 |
Correct |
7 ms |
9932 KB |
Output is correct |
12 |
Correct |
5 ms |
9880 KB |
Output is correct |
13 |
Correct |
6 ms |
10684 KB |
Output is correct |
14 |
Correct |
7 ms |
11592 KB |
Output is correct |
15 |
Correct |
9 ms |
12100 KB |
Output is correct |
16 |
Correct |
8 ms |
13256 KB |
Output is correct |
17 |
Correct |
7 ms |
10408 KB |
Output is correct |
18 |
Correct |
8 ms |
10832 KB |
Output is correct |
19 |
Correct |
9 ms |
11108 KB |
Output is correct |
20 |
Correct |
11 ms |
11128 KB |
Output is correct |
21 |
Correct |
9 ms |
10428 KB |
Output is correct |
22 |
Correct |
8 ms |
11032 KB |
Output is correct |
23 |
Correct |
10 ms |
11464 KB |
Output is correct |
24 |
Correct |
12 ms |
11648 KB |
Output is correct |
25 |
Correct |
193 ms |
89164 KB |
Output is correct |
26 |
Correct |
280 ms |
135792 KB |
Output is correct |
27 |
Correct |
337 ms |
192020 KB |
Output is correct |
28 |
Correct |
388 ms |
245680 KB |
Output is correct |
29 |
Correct |
250 ms |
44136 KB |
Output is correct |
30 |
Correct |
394 ms |
96040 KB |
Output is correct |
31 |
Correct |
514 ms |
88500 KB |
Output is correct |
32 |
Correct |
624 ms |
143264 KB |
Output is correct |
33 |
Correct |
224 ms |
68096 KB |
Output is correct |
34 |
Correct |
308 ms |
114676 KB |
Output is correct |
35 |
Correct |
354 ms |
139412 KB |
Output is correct |
36 |
Correct |
433 ms |
210656 KB |
Output is correct |
37 |
Correct |
214 ms |
88232 KB |
Output is correct |
38 |
Correct |
312 ms |
132624 KB |
Output is correct |
39 |
Correct |
361 ms |
202200 KB |
Output is correct |
40 |
Correct |
382 ms |
245768 KB |
Output is correct |
41 |
Correct |
279 ms |
58152 KB |
Output is correct |
42 |
Correct |
393 ms |
94980 KB |
Output is correct |
43 |
Correct |
482 ms |
91144 KB |
Output is correct |
44 |
Correct |
666 ms |
151108 KB |
Output is correct |
45 |
Correct |
216 ms |
66612 KB |
Output is correct |
46 |
Correct |
300 ms |
115064 KB |
Output is correct |
47 |
Correct |
353 ms |
138516 KB |
Output is correct |
48 |
Correct |
428 ms |
211000 KB |
Output is correct |