#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
// #define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define repin rep(i,0,n)
#define di(a) int a;cin>>a;
#define precise(i) cout<<fixed<<setprecision(i)
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define take(a,n) for(int j=0;j<n;j++) cin>>a[j];
#define give(a,n) for(int j=0;j<n;j++) cout<<a[j]<<' ';
#define vpii vector<pair<int,int>>
#define sis string s;
#define sin string s;cin>>s;
#define db double
#define be(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bpc(x) __builtin_popcountll(x)
#define btz(x) __builtin_ctz(x)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
const long long INF=1e18;
const long long M=1e9+7;
const long long MM=998244353;
int power( int N, int M){
int power = N, sum = 1;
if(N == 0) sum = 0;
while(M > 0){if((M & 1) == 1){sum *= power;}
power = power * power;M = M >> 1;}
return sum;
}
const int N=200001;
vector<pii> adj[N];
int st[N],en[N],et=0;
int d[N];
void dfs(int current,int par){
st[current]=et++;
for(auto next_vertex : adj[current]){
if(par == next_vertex.ff)continue;
d[next_vertex.ff]=d[current]^(next_vertex.ss);
dfs(next_vertex.ff,current);
}
en[current]=et;
}
const int SZ = 3200005;
const int MXBIT = 30;
si s[SZ];
int nex[SZ][2],num = 0;
void ins(int node) {
int x = d[node];
int cur = 0;
s[cur].insert(st[node]);
rrep(i,MXBIT,0) {
int t = (x>>i)&1;
if (!nex[cur][t]) {nex[cur][t] = ++num;}
cur = nex[cur][t];
s[cur].insert(st[node]);
}
}
int test(int a,int b) {
int x = d[a];
int cur = 0;
rrep(i,MXBIT,0) {
int t = ((x>>i)&1)^1;
if (!nex[cur][t]){
t^=1;
}
else{
auto it = s[nex[cur][t]].lb(st[b]);
if(it != s[nex[cur][t]].end()){
int res = *(it);
if(res >= en[b])t^=1;
}
else t^=1;
}
cur = nex[cur][t]; if (t) x ^= 1<<i;
}
return x;
}
void solve()
{
vector<pair<string, pii>> qry;
int node = 1;
int q;cin>>q;
rep(i,0,q){
string op;
cin>>op;
int a,b;
cin>>a>>b;
qry.pb({op.substr(0,1),{a,b}});
if(op == "Add"){
node++;
adj[a].pb({node,b});
}
}
dfs(1,0);
rep(i,1,node+1)adj[i].clear();
node = 1;
ins(1);
rep(i,0,q){
string op = qry[i].ff;
int a = qry[i].ss.ff;
int b = qry[i].ss.ss;
if(op == "A"){
node++;
ins(node);
}
else{
int ans = test(a,b);
// cout<<"ans"<<endl;
cout<<ans<<'\n';
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef NCR
init();
#endif
#ifdef SIEVE
sieve();
#endif
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
155340 KB |
Output is correct |
2 |
Correct |
69 ms |
155372 KB |
Output is correct |
3 |
Correct |
73 ms |
155480 KB |
Output is correct |
4 |
Correct |
65 ms |
155640 KB |
Output is correct |
5 |
Correct |
68 ms |
155412 KB |
Output is correct |
6 |
Correct |
63 ms |
155416 KB |
Output is correct |
7 |
Correct |
66 ms |
155468 KB |
Output is correct |
8 |
Correct |
70 ms |
155564 KB |
Output is correct |
9 |
Correct |
67 ms |
155400 KB |
Output is correct |
10 |
Correct |
69 ms |
155380 KB |
Output is correct |
11 |
Correct |
67 ms |
155528 KB |
Output is correct |
12 |
Correct |
67 ms |
155532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
155340 KB |
Output is correct |
2 |
Correct |
69 ms |
155372 KB |
Output is correct |
3 |
Correct |
73 ms |
155480 KB |
Output is correct |
4 |
Correct |
65 ms |
155640 KB |
Output is correct |
5 |
Correct |
68 ms |
155412 KB |
Output is correct |
6 |
Correct |
63 ms |
155416 KB |
Output is correct |
7 |
Correct |
66 ms |
155468 KB |
Output is correct |
8 |
Correct |
70 ms |
155564 KB |
Output is correct |
9 |
Correct |
67 ms |
155400 KB |
Output is correct |
10 |
Correct |
69 ms |
155380 KB |
Output is correct |
11 |
Correct |
67 ms |
155528 KB |
Output is correct |
12 |
Correct |
67 ms |
155532 KB |
Output is correct |
13 |
Correct |
86 ms |
156140 KB |
Output is correct |
14 |
Correct |
69 ms |
156856 KB |
Output is correct |
15 |
Correct |
67 ms |
157524 KB |
Output is correct |
16 |
Correct |
69 ms |
158204 KB |
Output is correct |
17 |
Correct |
77 ms |
156084 KB |
Output is correct |
18 |
Correct |
69 ms |
156744 KB |
Output is correct |
19 |
Correct |
71 ms |
157388 KB |
Output is correct |
20 |
Correct |
74 ms |
158284 KB |
Output is correct |
21 |
Correct |
74 ms |
156100 KB |
Output is correct |
22 |
Correct |
73 ms |
156748 KB |
Output is correct |
23 |
Correct |
72 ms |
157368 KB |
Output is correct |
24 |
Correct |
75 ms |
158012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
233788 KB |
Output is correct |
2 |
Correct |
1068 ms |
302376 KB |
Output is correct |
3 |
Correct |
1523 ms |
369464 KB |
Output is correct |
4 |
Correct |
1930 ms |
441500 KB |
Output is correct |
5 |
Correct |
656 ms |
233804 KB |
Output is correct |
6 |
Correct |
1186 ms |
299892 KB |
Output is correct |
7 |
Correct |
1748 ms |
364492 KB |
Output is correct |
8 |
Correct |
2294 ms |
429824 KB |
Output is correct |
9 |
Correct |
645 ms |
233896 KB |
Output is correct |
10 |
Correct |
1088 ms |
300924 KB |
Output is correct |
11 |
Correct |
1488 ms |
366908 KB |
Output is correct |
12 |
Correct |
1986 ms |
432276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
155340 KB |
Output is correct |
2 |
Correct |
69 ms |
155372 KB |
Output is correct |
3 |
Correct |
73 ms |
155480 KB |
Output is correct |
4 |
Correct |
65 ms |
155640 KB |
Output is correct |
5 |
Correct |
68 ms |
155412 KB |
Output is correct |
6 |
Correct |
63 ms |
155416 KB |
Output is correct |
7 |
Correct |
66 ms |
155468 KB |
Output is correct |
8 |
Correct |
70 ms |
155564 KB |
Output is correct |
9 |
Correct |
67 ms |
155400 KB |
Output is correct |
10 |
Correct |
69 ms |
155380 KB |
Output is correct |
11 |
Correct |
67 ms |
155528 KB |
Output is correct |
12 |
Correct |
67 ms |
155532 KB |
Output is correct |
13 |
Correct |
86 ms |
156140 KB |
Output is correct |
14 |
Correct |
69 ms |
156856 KB |
Output is correct |
15 |
Correct |
67 ms |
157524 KB |
Output is correct |
16 |
Correct |
69 ms |
158204 KB |
Output is correct |
17 |
Correct |
77 ms |
156084 KB |
Output is correct |
18 |
Correct |
69 ms |
156744 KB |
Output is correct |
19 |
Correct |
71 ms |
157388 KB |
Output is correct |
20 |
Correct |
74 ms |
158284 KB |
Output is correct |
21 |
Correct |
74 ms |
156100 KB |
Output is correct |
22 |
Correct |
73 ms |
156748 KB |
Output is correct |
23 |
Correct |
72 ms |
157368 KB |
Output is correct |
24 |
Correct |
75 ms |
158012 KB |
Output is correct |
25 |
Correct |
578 ms |
233788 KB |
Output is correct |
26 |
Correct |
1068 ms |
302376 KB |
Output is correct |
27 |
Correct |
1523 ms |
369464 KB |
Output is correct |
28 |
Correct |
1930 ms |
441500 KB |
Output is correct |
29 |
Correct |
656 ms |
233804 KB |
Output is correct |
30 |
Correct |
1186 ms |
299892 KB |
Output is correct |
31 |
Correct |
1748 ms |
364492 KB |
Output is correct |
32 |
Correct |
2294 ms |
429824 KB |
Output is correct |
33 |
Correct |
645 ms |
233896 KB |
Output is correct |
34 |
Correct |
1088 ms |
300924 KB |
Output is correct |
35 |
Correct |
1488 ms |
366908 KB |
Output is correct |
36 |
Correct |
1986 ms |
432276 KB |
Output is correct |
37 |
Correct |
965 ms |
237472 KB |
Output is correct |
38 |
Correct |
1559 ms |
305688 KB |
Output is correct |
39 |
Correct |
1931 ms |
374808 KB |
Output is correct |
40 |
Correct |
2223 ms |
441828 KB |
Output is correct |
41 |
Correct |
1081 ms |
234468 KB |
Output is correct |
42 |
Correct |
1746 ms |
299940 KB |
Output is correct |
43 |
Correct |
2156 ms |
364564 KB |
Output is correct |
44 |
Correct |
2564 ms |
429600 KB |
Output is correct |
45 |
Correct |
1113 ms |
234344 KB |
Output is correct |
46 |
Correct |
1762 ms |
301144 KB |
Output is correct |
47 |
Correct |
2130 ms |
366024 KB |
Output is correct |
48 |
Correct |
2284 ms |
432384 KB |
Output is correct |