# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
770108 |
2023-06-30T18:46:40 Z |
vjudge1 |
Klasika (COCI20_klasika) |
C++17 |
|
2071 ms |
524288 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif
const int lg = 31;
struct Trie {
public:
vector<vector<int>> trie;
vector<set<int>> st;
Trie() {
trie.push_back(vector<int> (2, -1));
st.push_back(set<int> ());
};
void add(int x, int ins) {
int t = 0;
for (int i = lg - 1; i >= 0; i--) {
int bit = (x >> i) & 1;
if (trie[t][bit] == -1) {
trie[t][bit] = (int) trie.size();
trie.emplace_back(2, -1);
st.push_back(set<int> ());
}
t = trie[t][bit];
st[t].insert(ins);
}
}
int get(int x, int low, int high) {
int t = 0;
int ret = 0;
auto isBad = [&](int bit) {
if (trie[t][bit] == -1) {
return true;
}
auto ptr = st[trie[t][bit]].lower_bound(low);
if (ptr != st[trie[t][bit]].end() && *ptr <= high) {
return false;
}
return true;
};
for (int i = lg - 1; i >= 0; i--) {
int bit = (x >> i) & 1;
bit ^= 1;
if (isBad(bit)) {
bit ^= 1;
} else {
ret |= (1 << i);
}
if (isBad(bit)) {
return 0;
}
t = trie[t][bit];
}
return ret;
};
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
int n = q + 1;
vector<vector<int>> adj(n);
vector<int> pref(n);
auto Add = [&](int x, int y, int w) {
adj[x].push_back(y);
pref[y] = pref[x] ^ w;
};
int cnt = 1;
vector<array<int, 3>> queries;
for (int i = 0; i < q; i++) {
string type;
cin >> type;
if (type == "Add") {
int x, w;
cin >> x >> w;
--x;
Add(x, cnt, w);
queries.push_back({1, cnt, 0});
++cnt;
} else {
int a, b;
cin >> a >> b;
--a, --b;
queries.push_back({2, a, b});
}
}
vector<int> in(n);
vector<int> out(n);
vector<int> euler_tour;
function<void(int)> Dfs = [&](int u) {
in[u] = (int) euler_tour.size();
euler_tour.push_back(u);
for (auto v : adj[u]) {
Dfs(v);
}
out[u] = (int) euler_tour.size() - 1;
};
Dfs(0);
Trie T;
T.add(0, 0);
for (int i = 0; i < (int) queries.size(); i++) {
int type = queries[i][0];
if (type == 1) {
int u = queries[i][1];
T.add(pref[u], in[u]);
} else {
int a = queries[i][1];
int b = queries[i][2];
cout << T.get(pref[a], in[b], out[b]) << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
832 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
832 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
2240 KB |
Output is correct |
14 |
Correct |
5 ms |
4024 KB |
Output is correct |
15 |
Correct |
7 ms |
4960 KB |
Output is correct |
16 |
Correct |
9 ms |
7796 KB |
Output is correct |
17 |
Correct |
4 ms |
2124 KB |
Output is correct |
18 |
Correct |
6 ms |
4040 KB |
Output is correct |
19 |
Correct |
7 ms |
4800 KB |
Output is correct |
20 |
Correct |
8 ms |
6080 KB |
Output is correct |
21 |
Correct |
4 ms |
2124 KB |
Output is correct |
22 |
Correct |
6 ms |
4036 KB |
Output is correct |
23 |
Correct |
7 ms |
4800 KB |
Output is correct |
24 |
Correct |
11 ms |
6080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
838 ms |
140360 KB |
Output is correct |
2 |
Correct |
1479 ms |
276256 KB |
Output is correct |
3 |
Correct |
2071 ms |
369352 KB |
Output is correct |
4 |
Runtime error |
1984 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
824 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
832 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
4 ms |
2240 KB |
Output is correct |
14 |
Correct |
5 ms |
4024 KB |
Output is correct |
15 |
Correct |
7 ms |
4960 KB |
Output is correct |
16 |
Correct |
9 ms |
7796 KB |
Output is correct |
17 |
Correct |
4 ms |
2124 KB |
Output is correct |
18 |
Correct |
6 ms |
4040 KB |
Output is correct |
19 |
Correct |
7 ms |
4800 KB |
Output is correct |
20 |
Correct |
8 ms |
6080 KB |
Output is correct |
21 |
Correct |
4 ms |
2124 KB |
Output is correct |
22 |
Correct |
6 ms |
4036 KB |
Output is correct |
23 |
Correct |
7 ms |
4800 KB |
Output is correct |
24 |
Correct |
11 ms |
6080 KB |
Output is correct |
25 |
Correct |
838 ms |
140360 KB |
Output is correct |
26 |
Correct |
1479 ms |
276256 KB |
Output is correct |
27 |
Correct |
2071 ms |
369352 KB |
Output is correct |
28 |
Runtime error |
1984 ms |
524288 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |