#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'
struct node{
int s,e,m;
vector<int> val;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,int j){
val.push_back(j);
if (s==e) return;
else if (i<=m) l->update(i,j);
else r->update(i,j);
}
int query(int i,int j,int k){
if (s==i && e==j){
int ans=0;
for (auto &it:val) ans=max(ans,it^k);
return ans;
}
else if (j<=m) return l->query(i,j,k);
else if (m<i) return r->query(i,j,k);
else return max(l->query(i,m,k),r->query(m+1,j,k));
}
}*root=new node(0,300005);
struct Q{
char t;
int a,b;
Q (char _t,int _a,int _b){
t=_t,a=_a,b=_b;
}
};
int n;
vector<int> al[300005];
int val[300005];
int in[300005];
int out[300005];
int DFS_TIME=0;
void dfs(int i,int p){
in[i]=++DFS_TIME;
for (auto &it:al[i]){
if (it==p) continue;
dfs(it,i);
}
out[i]=DFS_TIME;
}
vector<Q> queries;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
string s;
int a,b;
for (int x=0;x<n;x++){
cin>>s>>a>>b;
queries.push_back(Q(s[0],a,b));
}
int index=2;
for (auto &it:queries){
if (it.t=='A'){
al[it.a].push_back(index);
al[index].push_back(it.a);
val[index]=val[it.a]^it.b;
index++;
}
}
dfs(1,-1);
//for (int x=1;x<index;x++) cout<<val[x]<<" "<<in[x]<<" "<<out[x]<<endl;
root->update(in[1],val[1]); //oof
index=2;
for (auto &it:queries){
if (it.t=='A'){
//cout<<in[index]<<" "<<val[index]<<endl;
root->update(in[index],val[index]);
index++;
}
else{
//cout<<in[it.b]<<" "<<out[it.b]<<" "<<val[it.a]<<endl;
cout<<root->query(in[it.b],out[it.b],val[it.a])<<endl;
}
}
}
Compilation message
klasika.cpp: In constructor 'node::node(int, int)':
klasika.cpp:15:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
s=_s,e=_e,m=s+e>>1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
44928 KB |
Output is correct |
2 |
Correct |
41 ms |
44920 KB |
Output is correct |
3 |
Correct |
42 ms |
44920 KB |
Output is correct |
4 |
Correct |
47 ms |
45056 KB |
Output is correct |
5 |
Correct |
41 ms |
45048 KB |
Output is correct |
6 |
Correct |
40 ms |
44920 KB |
Output is correct |
7 |
Correct |
39 ms |
44920 KB |
Output is correct |
8 |
Correct |
44 ms |
45048 KB |
Output is correct |
9 |
Correct |
41 ms |
44920 KB |
Output is correct |
10 |
Correct |
41 ms |
45048 KB |
Output is correct |
11 |
Correct |
41 ms |
44920 KB |
Output is correct |
12 |
Correct |
41 ms |
45048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
44928 KB |
Output is correct |
2 |
Correct |
41 ms |
44920 KB |
Output is correct |
3 |
Correct |
42 ms |
44920 KB |
Output is correct |
4 |
Correct |
47 ms |
45056 KB |
Output is correct |
5 |
Correct |
41 ms |
45048 KB |
Output is correct |
6 |
Correct |
40 ms |
44920 KB |
Output is correct |
7 |
Correct |
39 ms |
44920 KB |
Output is correct |
8 |
Correct |
44 ms |
45048 KB |
Output is correct |
9 |
Correct |
41 ms |
44920 KB |
Output is correct |
10 |
Correct |
41 ms |
45048 KB |
Output is correct |
11 |
Correct |
41 ms |
44920 KB |
Output is correct |
12 |
Correct |
41 ms |
45048 KB |
Output is correct |
13 |
Correct |
42 ms |
45176 KB |
Output is correct |
14 |
Correct |
43 ms |
45176 KB |
Output is correct |
15 |
Correct |
42 ms |
45304 KB |
Output is correct |
16 |
Correct |
43 ms |
45440 KB |
Output is correct |
17 |
Correct |
47 ms |
45176 KB |
Output is correct |
18 |
Correct |
43 ms |
45176 KB |
Output is correct |
19 |
Correct |
42 ms |
45304 KB |
Output is correct |
20 |
Correct |
42 ms |
45304 KB |
Output is correct |
21 |
Correct |
41 ms |
45048 KB |
Output is correct |
22 |
Correct |
41 ms |
45176 KB |
Output is correct |
23 |
Correct |
50 ms |
45304 KB |
Output is correct |
24 |
Correct |
43 ms |
45304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3843 ms |
59096 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
69004 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
44928 KB |
Output is correct |
2 |
Correct |
41 ms |
44920 KB |
Output is correct |
3 |
Correct |
42 ms |
44920 KB |
Output is correct |
4 |
Correct |
47 ms |
45056 KB |
Output is correct |
5 |
Correct |
41 ms |
45048 KB |
Output is correct |
6 |
Correct |
40 ms |
44920 KB |
Output is correct |
7 |
Correct |
39 ms |
44920 KB |
Output is correct |
8 |
Correct |
44 ms |
45048 KB |
Output is correct |
9 |
Correct |
41 ms |
44920 KB |
Output is correct |
10 |
Correct |
41 ms |
45048 KB |
Output is correct |
11 |
Correct |
41 ms |
44920 KB |
Output is correct |
12 |
Correct |
41 ms |
45048 KB |
Output is correct |
13 |
Correct |
42 ms |
45176 KB |
Output is correct |
14 |
Correct |
43 ms |
45176 KB |
Output is correct |
15 |
Correct |
42 ms |
45304 KB |
Output is correct |
16 |
Correct |
43 ms |
45440 KB |
Output is correct |
17 |
Correct |
47 ms |
45176 KB |
Output is correct |
18 |
Correct |
43 ms |
45176 KB |
Output is correct |
19 |
Correct |
42 ms |
45304 KB |
Output is correct |
20 |
Correct |
42 ms |
45304 KB |
Output is correct |
21 |
Correct |
41 ms |
45048 KB |
Output is correct |
22 |
Correct |
41 ms |
45176 KB |
Output is correct |
23 |
Correct |
50 ms |
45304 KB |
Output is correct |
24 |
Correct |
43 ms |
45304 KB |
Output is correct |
25 |
Correct |
3843 ms |
59096 KB |
Output is correct |
26 |
Execution timed out |
5083 ms |
69004 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |