# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
638299 |
2022-09-05T08:42:25 Z |
iee |
Klasika (COCI20_klasika) |
C++17 |
|
2870 ms |
485032 KB |
// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);
template <class T> void read(T &x) {
x = 0; int f = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
x *= f;
}
int main() {
int TT = 1; // cin >> TT;
rep(CAS, 1, TT)
work(CAS);
return 0;
}
const int N = 3e5 + 5, M = 4e6 + 5;
int n, dfn_l[N], dfn_r[N], trie[M][3], tot = 1, idx, val[N];
int q;
int qry[N][3];
set<int> s[M];
vector<pair<int, int>> e[N];
void dfs(int u, int pr) {
dfn_l[u] = ++idx;
for (auto ver: e[u]) {
int v, w;
tie(v, w) = ver;
if (v == pr) continue;
val[v] = (val[u] ^ w);
dfs(v, u);
}
dfn_r[u] = idx;
}
void insert(int x, int dfn) {
int cur = 1;
s[cur].emplace(dfn);
per(i, 30, 0) {
int &to = trie[cur][x >> i & 1];
if (!to) to = ++tot;
cur = to;
s[cur].emplace(dfn);
}
}
int query(int x, int l, int r) {
int cur = 1, ans = 0;
per(i, 30, 0) {
int to = trie[cur][x >> i & 1 ^ 1];
bool ok = !!to;
auto it = s[to].lower_bound(l);
ok &= it != s[to].end() && (*it) <= r;
if (ok) cur = to, ans += (1 << i);
else cur = trie[cur][x >> i & 1];
}
return ans;
}
void work(int CASE) {
scanf("%d", &q);
++n;
rep(i, 1, q) {
char op[10];
scanf("%s%d%d", op, &qry[i][1], &qry[i][2]);
if (op[0] == 'A') {
qry[i][0] = 1;
++n;
e[qry[i][1]].emplace_back(n, qry[i][2]);
e[n].emplace_back(qry[i][1], qry[i][2]);
qry[i][1] = n;
} else {
qry[i][0] = 0;
}
}
dfs(1, 0);
insert(0, 1);
rep(i, 1, q) {
if (qry[i][0]) {
insert(val[qry[i][1]], dfn_l[qry[i][1]]);
} else {
printf("%d\n", query(val[qry[i][1]], dfn_l[qry[i][2]], dfn_r[qry[i][2]]));
}
}
}
Compilation message
klasika.cpp: In function 'int query(int, int, int)':
klasika.cpp:62:31: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
62 | int to = trie[cur][x >> i & 1 ^ 1];
| ~~~~~~~^~~
klasika.cpp: In function 'void work(int)':
klasika.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
klasika.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf("%s%d%d", op, &qry[i][1], &qry[i][2]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
195232 KB |
Output is correct |
2 |
Correct |
98 ms |
195384 KB |
Output is correct |
3 |
Correct |
93 ms |
195404 KB |
Output is correct |
4 |
Correct |
100 ms |
195420 KB |
Output is correct |
5 |
Correct |
96 ms |
195284 KB |
Output is correct |
6 |
Correct |
100 ms |
195328 KB |
Output is correct |
7 |
Correct |
104 ms |
195356 KB |
Output is correct |
8 |
Correct |
95 ms |
195464 KB |
Output is correct |
9 |
Correct |
99 ms |
195336 KB |
Output is correct |
10 |
Correct |
95 ms |
195400 KB |
Output is correct |
11 |
Correct |
97 ms |
195480 KB |
Output is correct |
12 |
Correct |
95 ms |
195424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
195232 KB |
Output is correct |
2 |
Correct |
98 ms |
195384 KB |
Output is correct |
3 |
Correct |
93 ms |
195404 KB |
Output is correct |
4 |
Correct |
100 ms |
195420 KB |
Output is correct |
5 |
Correct |
96 ms |
195284 KB |
Output is correct |
6 |
Correct |
100 ms |
195328 KB |
Output is correct |
7 |
Correct |
104 ms |
195356 KB |
Output is correct |
8 |
Correct |
95 ms |
195464 KB |
Output is correct |
9 |
Correct |
99 ms |
195336 KB |
Output is correct |
10 |
Correct |
95 ms |
195400 KB |
Output is correct |
11 |
Correct |
97 ms |
195480 KB |
Output is correct |
12 |
Correct |
95 ms |
195424 KB |
Output is correct |
13 |
Correct |
95 ms |
196044 KB |
Output is correct |
14 |
Correct |
99 ms |
196772 KB |
Output is correct |
15 |
Correct |
99 ms |
197572 KB |
Output is correct |
16 |
Correct |
103 ms |
198232 KB |
Output is correct |
17 |
Correct |
98 ms |
196004 KB |
Output is correct |
18 |
Correct |
99 ms |
196712 KB |
Output is correct |
19 |
Correct |
103 ms |
197580 KB |
Output is correct |
20 |
Correct |
118 ms |
198044 KB |
Output is correct |
21 |
Correct |
98 ms |
195944 KB |
Output is correct |
22 |
Correct |
100 ms |
196756 KB |
Output is correct |
23 |
Correct |
103 ms |
197492 KB |
Output is correct |
24 |
Correct |
101 ms |
198032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
735 ms |
273576 KB |
Output is correct |
2 |
Correct |
1241 ms |
344716 KB |
Output is correct |
3 |
Correct |
1763 ms |
413980 KB |
Output is correct |
4 |
Correct |
2279 ms |
484660 KB |
Output is correct |
5 |
Correct |
805 ms |
271608 KB |
Output is correct |
6 |
Correct |
1378 ms |
340608 KB |
Output is correct |
7 |
Correct |
1941 ms |
407736 KB |
Output is correct |
8 |
Correct |
2583 ms |
476140 KB |
Output is correct |
9 |
Correct |
796 ms |
271344 KB |
Output is correct |
10 |
Correct |
1262 ms |
341400 KB |
Output is correct |
11 |
Correct |
1780 ms |
409888 KB |
Output is correct |
12 |
Correct |
2253 ms |
477844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
195232 KB |
Output is correct |
2 |
Correct |
98 ms |
195384 KB |
Output is correct |
3 |
Correct |
93 ms |
195404 KB |
Output is correct |
4 |
Correct |
100 ms |
195420 KB |
Output is correct |
5 |
Correct |
96 ms |
195284 KB |
Output is correct |
6 |
Correct |
100 ms |
195328 KB |
Output is correct |
7 |
Correct |
104 ms |
195356 KB |
Output is correct |
8 |
Correct |
95 ms |
195464 KB |
Output is correct |
9 |
Correct |
99 ms |
195336 KB |
Output is correct |
10 |
Correct |
95 ms |
195400 KB |
Output is correct |
11 |
Correct |
97 ms |
195480 KB |
Output is correct |
12 |
Correct |
95 ms |
195424 KB |
Output is correct |
13 |
Correct |
95 ms |
196044 KB |
Output is correct |
14 |
Correct |
99 ms |
196772 KB |
Output is correct |
15 |
Correct |
99 ms |
197572 KB |
Output is correct |
16 |
Correct |
103 ms |
198232 KB |
Output is correct |
17 |
Correct |
98 ms |
196004 KB |
Output is correct |
18 |
Correct |
99 ms |
196712 KB |
Output is correct |
19 |
Correct |
103 ms |
197580 KB |
Output is correct |
20 |
Correct |
118 ms |
198044 KB |
Output is correct |
21 |
Correct |
98 ms |
195944 KB |
Output is correct |
22 |
Correct |
100 ms |
196756 KB |
Output is correct |
23 |
Correct |
103 ms |
197492 KB |
Output is correct |
24 |
Correct |
101 ms |
198032 KB |
Output is correct |
25 |
Correct |
735 ms |
273576 KB |
Output is correct |
26 |
Correct |
1241 ms |
344716 KB |
Output is correct |
27 |
Correct |
1763 ms |
413980 KB |
Output is correct |
28 |
Correct |
2279 ms |
484660 KB |
Output is correct |
29 |
Correct |
805 ms |
271608 KB |
Output is correct |
30 |
Correct |
1378 ms |
340608 KB |
Output is correct |
31 |
Correct |
1941 ms |
407736 KB |
Output is correct |
32 |
Correct |
2583 ms |
476140 KB |
Output is correct |
33 |
Correct |
796 ms |
271344 KB |
Output is correct |
34 |
Correct |
1262 ms |
341400 KB |
Output is correct |
35 |
Correct |
1780 ms |
409888 KB |
Output is correct |
36 |
Correct |
2253 ms |
477844 KB |
Output is correct |
37 |
Correct |
1184 ms |
274524 KB |
Output is correct |
38 |
Correct |
1705 ms |
345040 KB |
Output is correct |
39 |
Correct |
2148 ms |
416044 KB |
Output is correct |
40 |
Correct |
2487 ms |
485032 KB |
Output is correct |
41 |
Correct |
1328 ms |
272180 KB |
Output is correct |
42 |
Correct |
1938 ms |
340612 KB |
Output is correct |
43 |
Correct |
2459 ms |
408144 KB |
Output is correct |
44 |
Correct |
2870 ms |
475600 KB |
Output is correct |
45 |
Correct |
1363 ms |
271700 KB |
Output is correct |
46 |
Correct |
1876 ms |
341576 KB |
Output is correct |
47 |
Correct |
2231 ms |
408948 KB |
Output is correct |
48 |
Correct |
2591 ms |
477872 KB |
Output is correct |