#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
typedef pair<int,int> ii;
typedef pair<char,ii> Query;
vector<Query> queries;
vector<int> adjlist[N];
const int INF = 1000000000;
int num[N], l[N], r[N];
int ct = 1;
struct node{
int s,e,m;
set<int> v;
node *l = NULL, *r = NULL;
node (int _s, int _e): s(_s), e(_e){
m = (s+e)/2;
v.insert(INF);
}
void up(int x, int nv){
//printf("update %d %d %d\n",s,e,x);
v.insert(nv);
if (s == e){
return;
}
if (x <= m){
if (l == NULL) l = new node(s,m);
l->up(x,nv);
}
else{
if (r == NULL) r = new node(m+1,e);
r->up(x,nv);
}
}
int query(int id, int x, int L, int R){
//printf("segment tree: %d %d %d %d\n",s,e,id,x);
if (s == e){
return s^x;
}
if (x & (1<<id)){
//printf("prefer left\n");
if (l == NULL || *(l->v.lower_bound(L)) > R){
//printf("right anyway\n");
return r->query(id-1,x,L,R);
}
else return l->query(id-1,x,L,R);
}
else{
//printf("prefer right\n");
if (r == NULL || *(r->v.lower_bound(L)) > R) {
//printf("left anyway\n");
return l->query(id-1,x,L,R);
}
else return r->query(id-1,x,L,R);
}
}
}*root;
void dfs(int u, int p){
l[u] = ct++;
for (auto v : adjlist[u]){
if (v == p) continue;
dfs(v,u);
}
r[u] = ct++;
}
int main() {
int q;
cin >> q;
root = new node(0,(int)((unsigned)(1<<31)-1));
while (q--) {
string Q;
int a,b;
cin >> Q >> a >> b;
queries.push_back({Q[0],{a,b}});
if (Q == "Add"){
num[++ct] = num[a]^b;
adjlist[a].push_back(ct);
}
}
ct = 1;
dfs(1,-1);
root->up(0,l[1]);
ct = 1;
for (auto qu : queries){
char Q = qu.first;
int a = qu.second.first, b = qu.second.second;
if (Q == 'A'){
ct++;
root->up(num[ct],l[ct]);
}
else{
printf("%d\n",root->query(30,num[a],l[b],r[b]));
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
7 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 |
7 ms |
5248 KB |
Output is correct |
6 |
Correct |
9 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5632 KB |
Output is correct |
8 |
Correct |
10 ms |
5760 KB |
Output is correct |
9 |
Correct |
7 ms |
5248 KB |
Output is correct |
10 |
Correct |
9 ms |
5504 KB |
Output is correct |
11 |
Correct |
9 ms |
5632 KB |
Output is correct |
12 |
Correct |
8 ms |
5760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
7 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 |
7 ms |
5248 KB |
Output is correct |
6 |
Correct |
9 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5632 KB |
Output is correct |
8 |
Correct |
10 ms |
5760 KB |
Output is correct |
9 |
Correct |
7 ms |
5248 KB |
Output is correct |
10 |
Correct |
9 ms |
5504 KB |
Output is correct |
11 |
Correct |
9 ms |
5632 KB |
Output is correct |
12 |
Correct |
8 ms |
5760 KB |
Output is correct |
13 |
Correct |
14 ms |
7040 KB |
Output is correct |
14 |
Correct |
15 ms |
8960 KB |
Output is correct |
15 |
Correct |
18 ms |
10752 KB |
Output is correct |
16 |
Correct |
19 ms |
12288 KB |
Output is correct |
17 |
Correct |
13 ms |
7040 KB |
Output is correct |
18 |
Correct |
16 ms |
8832 KB |
Output is correct |
19 |
Correct |
20 ms |
10496 KB |
Output is correct |
20 |
Correct |
19 ms |
12160 KB |
Output is correct |
21 |
Correct |
13 ms |
7040 KB |
Output is correct |
22 |
Correct |
15 ms |
8832 KB |
Output is correct |
23 |
Correct |
19 ms |
10624 KB |
Output is correct |
24 |
Correct |
20 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
912 ms |
161448 KB |
Output is correct |
2 |
Correct |
1529 ms |
306452 KB |
Output is correct |
3 |
Correct |
2116 ms |
442052 KB |
Output is correct |
4 |
Runtime error |
2326 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5248 KB |
Output is correct |
2 |
Correct |
7 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 |
7 ms |
5248 KB |
Output is correct |
6 |
Correct |
9 ms |
5376 KB |
Output is correct |
7 |
Correct |
8 ms |
5632 KB |
Output is correct |
8 |
Correct |
10 ms |
5760 KB |
Output is correct |
9 |
Correct |
7 ms |
5248 KB |
Output is correct |
10 |
Correct |
9 ms |
5504 KB |
Output is correct |
11 |
Correct |
9 ms |
5632 KB |
Output is correct |
12 |
Correct |
8 ms |
5760 KB |
Output is correct |
13 |
Correct |
14 ms |
7040 KB |
Output is correct |
14 |
Correct |
15 ms |
8960 KB |
Output is correct |
15 |
Correct |
18 ms |
10752 KB |
Output is correct |
16 |
Correct |
19 ms |
12288 KB |
Output is correct |
17 |
Correct |
13 ms |
7040 KB |
Output is correct |
18 |
Correct |
16 ms |
8832 KB |
Output is correct |
19 |
Correct |
20 ms |
10496 KB |
Output is correct |
20 |
Correct |
19 ms |
12160 KB |
Output is correct |
21 |
Correct |
13 ms |
7040 KB |
Output is correct |
22 |
Correct |
15 ms |
8832 KB |
Output is correct |
23 |
Correct |
19 ms |
10624 KB |
Output is correct |
24 |
Correct |
20 ms |
12160 KB |
Output is correct |
25 |
Correct |
912 ms |
161448 KB |
Output is correct |
26 |
Correct |
1529 ms |
306452 KB |
Output is correct |
27 |
Correct |
2116 ms |
442052 KB |
Output is correct |
28 |
Runtime error |
2326 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |