# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
494026 |
2021-12-13T19:39:47 Z |
Victor |
Klasika (COCI20_klasika) |
C++17 |
|
2240 ms |
524292 KB |
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
const int MAXN = 200001;
int xor_root[MAXN + 5], euler_id[MAXN + 5], sub_size[MAXN + 5], n = 1, cnt = 0;
struct Node {
Node *zero = 0, *one = 0;
set<int> nodes;
int node_val = 0;
void add(int val, int pos, int u) {
nodes.insert(euler_id[u]);
if (pos == -1) return;
if (val & (1 << pos)) {
if (one == 0) {
one = new Node;
one->node_val = node_val | (1 << pos);
one->nodes.insert(INF);
}
one->add(val, pos - 1, u);
} else {
if (zero == 0) {
zero = new Node;
zero->node_val = node_val;
zero->nodes.insert(INF);
}
zero->add(val, pos - 1, u);
}
}
int query(int val, int pos, int u) {
if (pos == -1) return node_val;
bool has_zero = 0;
if (zero && *zero->nodes.lower_bound(euler_id[u]) < euler_id[u] + sub_size[u]) has_zero = 1;
bool has_one = 0;
if (one && *one->nodes.lower_bound(euler_id[u]) < euler_id[u] + sub_size[u]) has_one = 1;
//cout<<"val = "<<val<<" pos = "<<pos<<" u = "<<u<<" has_zero = "<<has_zero<<" has_one = "<<has_one<<" node_val = "<<node_val<<endl;
if (!has_zero) return one->query(val, pos - 1, u);
if (!has_one) return zero->query(val, pos - 1, u);
if (val & (1 << pos))
return zero->query(val, pos - 1, u);
else
return one->query(val, pos - 1, u);
}
};
vii graph[MAXN + 5];
void dfs(int u, int cur_xor) {
sub_size[u] = 1;
euler_id[u] = cnt++;
xor_root[u] = cur_xor;
trav(edge, graph[u]) {
int v, w;
tie(v, w) = edge;
dfs(v, cur_xor ^ w);
sub_size[u] += sub_size[v];
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
vector<iii> queries;
int q;
cin >> q;
rep(i, 0, q) {
string type;
int a, b;
cin >> type >> a >> b;
queries.pb({type == "Add", {a, b}});
if (type == "Add") graph[a - 1].emplace_back(n++, b);
}
dfs(0, 0);
const int len = 30;
Node trie;
trie.add(0, len, 0);
cnt = 1;
rep(i, 0, q) {
int type;
type = queries[i].first;
if (type) {
int u, w;
tie(u, w) = queries[i].second;
trie.add(xor_root[cnt], len, cnt);
++cnt;
} else {
int u, v;
tie(u, v) = queries[i].second;
cout << (xor_root[u - 1] ^ trie.query(xor_root[u - 1], len, v - 1)) << endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5196 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5580 KB |
Output is correct |
4 |
Correct |
3 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5196 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5452 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
5 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5452 KB |
Output is correct |
11 |
Correct |
3 ms |
5580 KB |
Output is correct |
12 |
Correct |
4 ms |
5736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5196 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5580 KB |
Output is correct |
4 |
Correct |
3 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5196 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5452 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
5 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5452 KB |
Output is correct |
11 |
Correct |
3 ms |
5580 KB |
Output is correct |
12 |
Correct |
4 ms |
5736 KB |
Output is correct |
13 |
Correct |
9 ms |
6860 KB |
Output is correct |
14 |
Correct |
10 ms |
8524 KB |
Output is correct |
15 |
Correct |
12 ms |
10248 KB |
Output is correct |
16 |
Correct |
12 ms |
11724 KB |
Output is correct |
17 |
Correct |
8 ms |
6732 KB |
Output is correct |
18 |
Correct |
10 ms |
8396 KB |
Output is correct |
19 |
Correct |
12 ms |
10060 KB |
Output is correct |
20 |
Correct |
13 ms |
11596 KB |
Output is correct |
21 |
Correct |
8 ms |
6732 KB |
Output is correct |
22 |
Correct |
11 ms |
8524 KB |
Output is correct |
23 |
Correct |
11 ms |
10044 KB |
Output is correct |
24 |
Correct |
16 ms |
11584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
954 ms |
152032 KB |
Output is correct |
2 |
Correct |
1396 ms |
288932 KB |
Output is correct |
3 |
Correct |
1890 ms |
416804 KB |
Output is correct |
4 |
Runtime error |
2240 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5196 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5580 KB |
Output is correct |
4 |
Correct |
3 ms |
5708 KB |
Output is correct |
5 |
Correct |
4 ms |
5196 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5452 KB |
Output is correct |
8 |
Correct |
3 ms |
5708 KB |
Output is correct |
9 |
Correct |
5 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5452 KB |
Output is correct |
11 |
Correct |
3 ms |
5580 KB |
Output is correct |
12 |
Correct |
4 ms |
5736 KB |
Output is correct |
13 |
Correct |
9 ms |
6860 KB |
Output is correct |
14 |
Correct |
10 ms |
8524 KB |
Output is correct |
15 |
Correct |
12 ms |
10248 KB |
Output is correct |
16 |
Correct |
12 ms |
11724 KB |
Output is correct |
17 |
Correct |
8 ms |
6732 KB |
Output is correct |
18 |
Correct |
10 ms |
8396 KB |
Output is correct |
19 |
Correct |
12 ms |
10060 KB |
Output is correct |
20 |
Correct |
13 ms |
11596 KB |
Output is correct |
21 |
Correct |
8 ms |
6732 KB |
Output is correct |
22 |
Correct |
11 ms |
8524 KB |
Output is correct |
23 |
Correct |
11 ms |
10044 KB |
Output is correct |
24 |
Correct |
16 ms |
11584 KB |
Output is correct |
25 |
Correct |
954 ms |
152032 KB |
Output is correct |
26 |
Correct |
1396 ms |
288932 KB |
Output is correct |
27 |
Correct |
1890 ms |
416804 KB |
Output is correct |
28 |
Runtime error |
2240 ms |
524292 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |