# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857100 |
2023-10-05T11:32:19 Z |
Jethro |
Klasika (COCI20_klasika) |
C++17 |
|
3453 ms |
524288 KB |
//Writed by: Jethro_
//----------------------
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 2e6 + 10;
int n, node = 1, i, root, val, in[N], out[N], cnt = 0, Xor[N], LG = 31, child[N][2], cnt2 = 0;
vector<pair<int, int>> a[N];
set<int> save[N];
pair<int, int> query[N];
string type[N];
void add() {
cin >> n;
for(i = 1; i <= n; ++i) {
cin >> type[i];
if(type[i] == "Add") {
cin >> root >> val;
a[++node].push_back({root, val});
a[root].push_back({node, val});
query[i] = {node, node};
}else {
cin >> root >> val;
query[i] = {root, val};
}
}
}
void dfs(int u, int p) {
in[u] = ++cnt;
for(auto [v, w] : a[u]) {
if(v == p) continue;
Xor[v] = Xor[u] ^ w;
dfs(v, u);
}
out[u] = cnt;
}
void ADD(int s, int id) {
int u = 0;
for(int i = LG; i >= 0; --i) {
int k = (s >> i) & 1;
if(child[u][k] == -1) {
child[u][k] = ++cnt2;
}
u = child[u][k];
save[u].insert(in[id]);
}
}
void get(int s, int l, int r) {
int u = 0, res = 0;
for(int i = LG; i >= 0; --i) {
int k = (s >> i) & 1, t = child[u][k ^ 1];
if(t != -1){
auto x = save[t].lower_bound(l);
if(x != save[t].end() && (*x) <= r) {
u = t;
res += (1 << i);
}else {
u = child[u][k];
}
}else {
u = child[u][k];
}
}
cout << res << '\n';
}
void solve() {
memset(child, -1, sizeof child);
dfs(1, 0);
ADD(0, 1);
for(i = 1; i <= n; ++i) {
auto [x, y] = query[i];
if(type[i] == "Add") {
ADD(Xor[x], y);
}else {
int now = Xor[x];
get(now, in[y], out[y]);
}
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
add();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
224156 KB |
Output is correct |
2 |
Correct |
41 ms |
224316 KB |
Output is correct |
3 |
Correct |
43 ms |
224348 KB |
Output is correct |
4 |
Correct |
42 ms |
224340 KB |
Output is correct |
5 |
Correct |
43 ms |
224340 KB |
Output is correct |
6 |
Correct |
42 ms |
224364 KB |
Output is correct |
7 |
Correct |
43 ms |
224460 KB |
Output is correct |
8 |
Correct |
42 ms |
224344 KB |
Output is correct |
9 |
Correct |
44 ms |
224548 KB |
Output is correct |
10 |
Correct |
46 ms |
224336 KB |
Output is correct |
11 |
Correct |
45 ms |
224540 KB |
Output is correct |
12 |
Correct |
42 ms |
224348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
224156 KB |
Output is correct |
2 |
Correct |
41 ms |
224316 KB |
Output is correct |
3 |
Correct |
43 ms |
224348 KB |
Output is correct |
4 |
Correct |
42 ms |
224340 KB |
Output is correct |
5 |
Correct |
43 ms |
224340 KB |
Output is correct |
6 |
Correct |
42 ms |
224364 KB |
Output is correct |
7 |
Correct |
43 ms |
224460 KB |
Output is correct |
8 |
Correct |
42 ms |
224344 KB |
Output is correct |
9 |
Correct |
44 ms |
224548 KB |
Output is correct |
10 |
Correct |
46 ms |
224336 KB |
Output is correct |
11 |
Correct |
45 ms |
224540 KB |
Output is correct |
12 |
Correct |
42 ms |
224348 KB |
Output is correct |
13 |
Correct |
44 ms |
224860 KB |
Output is correct |
14 |
Correct |
46 ms |
225368 KB |
Output is correct |
15 |
Correct |
52 ms |
226132 KB |
Output is correct |
16 |
Correct |
46 ms |
226664 KB |
Output is correct |
17 |
Correct |
44 ms |
224920 KB |
Output is correct |
18 |
Correct |
46 ms |
225388 KB |
Output is correct |
19 |
Correct |
46 ms |
226128 KB |
Output is correct |
20 |
Correct |
47 ms |
226640 KB |
Output is correct |
21 |
Correct |
44 ms |
224900 KB |
Output is correct |
22 |
Correct |
47 ms |
225364 KB |
Output is correct |
23 |
Correct |
45 ms |
226128 KB |
Output is correct |
24 |
Correct |
46 ms |
226644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
512 ms |
293752 KB |
Output is correct |
2 |
Correct |
976 ms |
357716 KB |
Output is correct |
3 |
Correct |
1349 ms |
420388 KB |
Output is correct |
4 |
Runtime error |
3453 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
224156 KB |
Output is correct |
2 |
Correct |
41 ms |
224316 KB |
Output is correct |
3 |
Correct |
43 ms |
224348 KB |
Output is correct |
4 |
Correct |
42 ms |
224340 KB |
Output is correct |
5 |
Correct |
43 ms |
224340 KB |
Output is correct |
6 |
Correct |
42 ms |
224364 KB |
Output is correct |
7 |
Correct |
43 ms |
224460 KB |
Output is correct |
8 |
Correct |
42 ms |
224344 KB |
Output is correct |
9 |
Correct |
44 ms |
224548 KB |
Output is correct |
10 |
Correct |
46 ms |
224336 KB |
Output is correct |
11 |
Correct |
45 ms |
224540 KB |
Output is correct |
12 |
Correct |
42 ms |
224348 KB |
Output is correct |
13 |
Correct |
44 ms |
224860 KB |
Output is correct |
14 |
Correct |
46 ms |
225368 KB |
Output is correct |
15 |
Correct |
52 ms |
226132 KB |
Output is correct |
16 |
Correct |
46 ms |
226664 KB |
Output is correct |
17 |
Correct |
44 ms |
224920 KB |
Output is correct |
18 |
Correct |
46 ms |
225388 KB |
Output is correct |
19 |
Correct |
46 ms |
226128 KB |
Output is correct |
20 |
Correct |
47 ms |
226640 KB |
Output is correct |
21 |
Correct |
44 ms |
224900 KB |
Output is correct |
22 |
Correct |
47 ms |
225364 KB |
Output is correct |
23 |
Correct |
45 ms |
226128 KB |
Output is correct |
24 |
Correct |
46 ms |
226644 KB |
Output is correct |
25 |
Correct |
512 ms |
293752 KB |
Output is correct |
26 |
Correct |
976 ms |
357716 KB |
Output is correct |
27 |
Correct |
1349 ms |
420388 KB |
Output is correct |
28 |
Runtime error |
3453 ms |
524288 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |