# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
223291 |
2020-04-15T06:53:34 Z |
lyc |
Klasika (COCI20_klasika) |
C++14 |
|
3984 ms |
503432 KB |
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_Q = 2e5+5;
const int MX_N = 2e5+5;
int Q;
struct Query { int t, x, y; } query[MX_Q]; // 0 for add, 1 for query
int N;
vector<pair<int,int>> al[MX_N];
int dt, pre[MX_N], pst[MX_N], dist[MX_N];
void dfs(int u) {
pre[u] = ++dt;
for (auto v : al[u]) {
dist[v.first] = dist[u] ^ v.second;
dfs(v.first);
}
pst[u] = dt;
}
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct node {
pbds_set<int> v;
node *l, *r;
node(): l(NULL), r(NULL) {}
void update(int depth, int bit, int bm, int x) {
//if (depth < 5) cout << "Updating node " << depth << " " << bit << " :: " << bm << " " << x << endl;
v.insert(x);
if (depth == 0) return;
if ((bm&(1<<(depth-1))) == 0) {
if (l == NULL) l = new node();
l->update(depth-1,0,bm,x);
} else {
if (r == NULL) r = new node();
r->update(depth-1,1,bm,x);
}
}
bool contains(int x, int y) {
return v.order_of_key(y+1) - v.order_of_key(x) > 0;
}
int query(int depth, int bit, int x, int y, int bm) {
//if (depth < 5) cout << "Querying node " << depth << " " << bit << " :: " << x << " " << y << " " << bm << " contains? " << contains(x,y) << " sz " << SZ(v) << endl;
if (depth == 0) return bit;
int b = bm&(1<<(depth-1));
if (l != NULL && l->contains(x,y) && (b || r == NULL || (!r->contains(x,y))))
return (bit<<depth) | l->query(depth-1,0,x,y,bm);
return (bit<<depth) | r->query(depth-1,1,x,y,bm);
}
} btree;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
N = 1;
cin >> Q;
FOR(i,1,Q){
string S; int X, Y; cin >> S >> X >> Y;
if (S == "Add") {
al[X].emplace_back(++N,Y);
query[i] = { 0,N,-1 };
} else {
query[i] = { 1,X,Y };
}
}
dt = 0, dist[1] = 0, dfs(1);
//FOR(i,1,N){
// cout << i << " :: " << pre[i] << " " << pst[i] << " :: " << dist[i] << endl;
//}
btree.update(31, 0, 0, 1);
FOR(i,1,Q){
Query q = query[i];
//cout << "query " << i << endl;
if (q.t == 0) {
btree.update(31, 0, dist[q.x], pre[q.x]);
} else {
cout << (dist[q.x] ^ btree.query(31, 0, pre[q.y], pst[q.y], dist[q.x])) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
8 ms |
5376 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
9 ms |
5760 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
10 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5504 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
9 |
Correct |
8 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5504 KB |
Output is correct |
11 |
Correct |
8 ms |
5632 KB |
Output is correct |
12 |
Correct |
9 ms |
5760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
8 ms |
5376 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
9 ms |
5760 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
10 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5504 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
9 |
Correct |
8 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5504 KB |
Output is correct |
11 |
Correct |
8 ms |
5632 KB |
Output is correct |
12 |
Correct |
9 ms |
5760 KB |
Output is correct |
13 |
Correct |
13 ms |
6784 KB |
Output is correct |
14 |
Correct |
15 ms |
8320 KB |
Output is correct |
15 |
Correct |
17 ms |
9856 KB |
Output is correct |
16 |
Correct |
19 ms |
11264 KB |
Output is correct |
17 |
Correct |
13 ms |
6784 KB |
Output is correct |
18 |
Correct |
15 ms |
8192 KB |
Output is correct |
19 |
Correct |
17 ms |
9728 KB |
Output is correct |
20 |
Correct |
18 ms |
11136 KB |
Output is correct |
21 |
Correct |
13 ms |
6784 KB |
Output is correct |
22 |
Correct |
15 ms |
8320 KB |
Output is correct |
23 |
Correct |
17 ms |
9856 KB |
Output is correct |
24 |
Correct |
19 ms |
11136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1877 ms |
141000 KB |
Output is correct |
2 |
Correct |
2646 ms |
265048 KB |
Output is correct |
3 |
Correct |
3192 ms |
384760 KB |
Output is correct |
4 |
Correct |
3693 ms |
503288 KB |
Output is correct |
5 |
Correct |
1470 ms |
140968 KB |
Output is correct |
6 |
Correct |
2274 ms |
263544 KB |
Output is correct |
7 |
Correct |
2890 ms |
380536 KB |
Output is correct |
8 |
Correct |
3374 ms |
497144 KB |
Output is correct |
9 |
Correct |
1548 ms |
140344 KB |
Output is correct |
10 |
Correct |
2291 ms |
264324 KB |
Output is correct |
11 |
Correct |
3151 ms |
382584 KB |
Output is correct |
12 |
Correct |
3949 ms |
498768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
8 ms |
5376 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
9 ms |
5760 KB |
Output is correct |
5 |
Correct |
8 ms |
5248 KB |
Output is correct |
6 |
Correct |
10 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5504 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
9 |
Correct |
8 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5504 KB |
Output is correct |
11 |
Correct |
8 ms |
5632 KB |
Output is correct |
12 |
Correct |
9 ms |
5760 KB |
Output is correct |
13 |
Correct |
13 ms |
6784 KB |
Output is correct |
14 |
Correct |
15 ms |
8320 KB |
Output is correct |
15 |
Correct |
17 ms |
9856 KB |
Output is correct |
16 |
Correct |
19 ms |
11264 KB |
Output is correct |
17 |
Correct |
13 ms |
6784 KB |
Output is correct |
18 |
Correct |
15 ms |
8192 KB |
Output is correct |
19 |
Correct |
17 ms |
9728 KB |
Output is correct |
20 |
Correct |
18 ms |
11136 KB |
Output is correct |
21 |
Correct |
13 ms |
6784 KB |
Output is correct |
22 |
Correct |
15 ms |
8320 KB |
Output is correct |
23 |
Correct |
17 ms |
9856 KB |
Output is correct |
24 |
Correct |
19 ms |
11136 KB |
Output is correct |
25 |
Correct |
1877 ms |
141000 KB |
Output is correct |
26 |
Correct |
2646 ms |
265048 KB |
Output is correct |
27 |
Correct |
3192 ms |
384760 KB |
Output is correct |
28 |
Correct |
3693 ms |
503288 KB |
Output is correct |
29 |
Correct |
1470 ms |
140968 KB |
Output is correct |
30 |
Correct |
2274 ms |
263544 KB |
Output is correct |
31 |
Correct |
2890 ms |
380536 KB |
Output is correct |
32 |
Correct |
3374 ms |
497144 KB |
Output is correct |
33 |
Correct |
1548 ms |
140344 KB |
Output is correct |
34 |
Correct |
2291 ms |
264324 KB |
Output is correct |
35 |
Correct |
3151 ms |
382584 KB |
Output is correct |
36 |
Correct |
3949 ms |
498768 KB |
Output is correct |
37 |
Correct |
2725 ms |
143096 KB |
Output is correct |
38 |
Correct |
3848 ms |
265644 KB |
Output is correct |
39 |
Correct |
3984 ms |
387600 KB |
Output is correct |
40 |
Correct |
3934 ms |
503432 KB |
Output is correct |
41 |
Correct |
2335 ms |
140664 KB |
Output is correct |
42 |
Correct |
2818 ms |
262688 KB |
Output is correct |
43 |
Correct |
3233 ms |
379904 KB |
Output is correct |
44 |
Correct |
3408 ms |
495672 KB |
Output is correct |
45 |
Correct |
2547 ms |
139896 KB |
Output is correct |
46 |
Correct |
3349 ms |
263500 KB |
Output is correct |
47 |
Correct |
3707 ms |
380480 KB |
Output is correct |
48 |
Correct |
3894 ms |
497980 KB |
Output is correct |