//~ #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200002;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,say=1,nodee=1,visit[li*30][5],xorr[li],l[li],r[li],x[li],y[li],q;
int cev;
char s[li][10];
//~ set<int> st[li];
vector<int> v,vec[li],vect;
vector<set<int>> st;
inline void build_trie(int xxx){
int node=1;
//~ cout<<xxx<<"*(*(*(\n";
for(int i=0;i<(int)v.size();i++){
auto it=st[node].lower_bound(l[xxx]);
int yess=0;
if(it!=st[node].end()){
if(*it<=r[xxx])yess=1;
}
if(yess==0)st[node].insert(l[xxx]);
if(visit[node][v[i]])node=visit[node][v[i]];
else{
st.resize(nodee+2);
visit[node][v[i]]=++nodee;
node=nodee;
}
}
auto it=st[node].lower_bound(l[xxx]);
int yess=0;
if(it!=st[node].end()){
if(*it<=r[xxx])yess=1;
}
if(yess==0)st[node].insert(l[xxx]);
}
inline void ask_trie(int xx){
int node=1;
//~ cout<<l[xx]<<" : : : "<<r[xx]<<endl;
for(int i=0;i<(int)v.size();i++){
auto it=st[visit[node][!v[i]]].lower_bound(l[xx]);
//~ if(xx==3 && node==1)cout<<node<<"****"<<endl;
//~ if(visit[node][!v[i]]){
int yess=0;
//~ cout<<*it<<endl;
if(it!=st[visit[node][!v[i]]].end()){
//~ if(xx==3)cout<<*it<<endl;
if(visit[node][!v[i]] && *it<=r[xx]){node=visit[node][!v[i]];vect.pb(1);yess=1;}
}
//~ }
if(yess==0 && visit[node][v[i]]){node=visit[node][v[i]];vect.pb(0);}
}
}
inline void dfs(int node,int ata){
l[node]=++q;
r[node]=q;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i];
if(go==ata)continue;
dfs(go,node);
r[node]=max(r[node],r[go]);
}
}
main(void){
//~ freopen("at.txt","r",stdin);
//~ freopen("att.txt","w",stdout);
scanf("%lld",&t);
//~ set.resize();
for(int i=1;i<=t;i++){
//~ int x,y;
scanf("%s %lld %lld",s[i],&x[i],&y[i]);
if(s[i][0]=='A'){
//~ xorr[++say]=(xorr[x[i]]^y[i]);
vec[x[i]].pb(++say);
vec[say].pb(x[i]);
//~ v.clear();
//~ while(at){
//~ v.pb(at%2);
//~ at/=2;
//~ }
//~ while((int)v.size()<35)v.pb(0);
//~ reverse(v.begin(),v.end());
//~ build_trie();
//~ continue;
}
//~ int at=xorr[x];
//~ v.clear();
//~ while(at){
//~ v.pb(at%2);
//~ at/=2;
//~ }
//~ while((int)v.size()<35)v.pb(0);
//~ reverse(v.begin(),v.end());
//~ vect.clear();
//~ ask_trie();
//~ reverse(vect.begin(),vect.end());
//~ int ans=0;
//~ for(int i=0;i<(int)vect.size();i++){
//~ if(vect[i]==1)ans=(ans^(1ll<<i));
//~ }
//~ printf("%lld\n",ans);
}
st.resize(2);
dfs(1,0);
//~ st.resize(say*30);
for(int i=1;i<=30;i++)v.pb(0);
build_trie(1);
//~ cout<<l[5]<<" : : "<<r[5]<<" : : "<<xorr[]endl;
say=1;
for(int i=1;i<=t;i++){
if(s[i][0]=='A'){
xorr[++say]=(xorr[x[i]]^y[i]);
//~ vec[x[i]].pb(say);
int at=xorr[say];
//~ vec[say].pb(x[i]);
v.clear();
while(at){
v.pb(at%2);
at/=2;
}
while((int)v.size()<30)v.pb(0);
reverse(v.begin(),v.end());
build_trie(say);
continue;
}
int at=xorr[x[i]];
v.clear();
while(at){
v.pb(at%2);
at/=2;
}
while((int)v.size()<30)v.pb(0);
reverse(v.begin(),v.end());
vect.clear();
ask_trie(y[i]);
reverse(vect.begin(),vect.end());
int ans=0;
for(int j=0;j<(int)vect.size();j++){
if(vect[j]==1)ans=(ans^(1ll<<j));
}
printf("%lld\n",ans);
}
//~ cout<<xorr[3]<<endl;
return 0;
}
Compilation message
klasika.cpp:90:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
klasika.cpp: In function 'int main()':
klasika.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&t);
~~~~~^~~~~~~~~~~
klasika.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s %lld %lld",s[i],&x[i],&y[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5248 KB |
Output is correct |
2 |
Correct |
4 ms |
5376 KB |
Output is correct |
3 |
Correct |
4 ms |
5504 KB |
Output is correct |
4 |
Correct |
4 ms |
5632 KB |
Output is correct |
5 |
Correct |
4 ms |
5248 KB |
Output is correct |
6 |
Correct |
4 ms |
5376 KB |
Output is correct |
7 |
Correct |
4 ms |
5504 KB |
Output is correct |
8 |
Correct |
4 ms |
5632 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
5 ms |
5504 KB |
Output is correct |
11 |
Correct |
4 ms |
5632 KB |
Output is correct |
12 |
Correct |
4 ms |
5632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5248 KB |
Output is correct |
2 |
Correct |
4 ms |
5376 KB |
Output is correct |
3 |
Correct |
4 ms |
5504 KB |
Output is correct |
4 |
Correct |
4 ms |
5632 KB |
Output is correct |
5 |
Correct |
4 ms |
5248 KB |
Output is correct |
6 |
Correct |
4 ms |
5376 KB |
Output is correct |
7 |
Correct |
4 ms |
5504 KB |
Output is correct |
8 |
Correct |
4 ms |
5632 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
5 ms |
5504 KB |
Output is correct |
11 |
Correct |
4 ms |
5632 KB |
Output is correct |
12 |
Correct |
4 ms |
5632 KB |
Output is correct |
13 |
Correct |
8 ms |
6812 KB |
Output is correct |
14 |
Correct |
11 ms |
8504 KB |
Output is correct |
15 |
Correct |
13 ms |
9268 KB |
Output is correct |
16 |
Correct |
15 ms |
11956 KB |
Output is correct |
17 |
Correct |
8 ms |
6844 KB |
Output is correct |
18 |
Correct |
11 ms |
8504 KB |
Output is correct |
19 |
Correct |
14 ms |
9140 KB |
Output is correct |
20 |
Correct |
14 ms |
10420 KB |
Output is correct |
21 |
Correct |
9 ms |
6844 KB |
Output is correct |
22 |
Correct |
11 ms |
8504 KB |
Output is correct |
23 |
Correct |
14 ms |
9140 KB |
Output is correct |
24 |
Correct |
15 ms |
10420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1010 ms |
132460 KB |
Output is correct |
2 |
Correct |
1720 ms |
259512 KB |
Output is correct |
3 |
Correct |
2408 ms |
341852 KB |
Output is correct |
4 |
Correct |
3223 ms |
524288 KB |
Output is correct |
5 |
Correct |
1052 ms |
133868 KB |
Output is correct |
6 |
Correct |
1805 ms |
260524 KB |
Output is correct |
7 |
Correct |
2523 ms |
343016 KB |
Output is correct |
8 |
Correct |
3284 ms |
522456 KB |
Output is correct |
9 |
Correct |
1047 ms |
134288 KB |
Output is correct |
10 |
Correct |
1812 ms |
260728 KB |
Output is correct |
11 |
Correct |
2534 ms |
344732 KB |
Output is correct |
12 |
Correct |
3316 ms |
522964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5248 KB |
Output is correct |
2 |
Correct |
4 ms |
5376 KB |
Output is correct |
3 |
Correct |
4 ms |
5504 KB |
Output is correct |
4 |
Correct |
4 ms |
5632 KB |
Output is correct |
5 |
Correct |
4 ms |
5248 KB |
Output is correct |
6 |
Correct |
4 ms |
5376 KB |
Output is correct |
7 |
Correct |
4 ms |
5504 KB |
Output is correct |
8 |
Correct |
4 ms |
5632 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
5 ms |
5504 KB |
Output is correct |
11 |
Correct |
4 ms |
5632 KB |
Output is correct |
12 |
Correct |
4 ms |
5632 KB |
Output is correct |
13 |
Correct |
8 ms |
6812 KB |
Output is correct |
14 |
Correct |
11 ms |
8504 KB |
Output is correct |
15 |
Correct |
13 ms |
9268 KB |
Output is correct |
16 |
Correct |
15 ms |
11956 KB |
Output is correct |
17 |
Correct |
8 ms |
6844 KB |
Output is correct |
18 |
Correct |
11 ms |
8504 KB |
Output is correct |
19 |
Correct |
14 ms |
9140 KB |
Output is correct |
20 |
Correct |
14 ms |
10420 KB |
Output is correct |
21 |
Correct |
9 ms |
6844 KB |
Output is correct |
22 |
Correct |
11 ms |
8504 KB |
Output is correct |
23 |
Correct |
14 ms |
9140 KB |
Output is correct |
24 |
Correct |
15 ms |
10420 KB |
Output is correct |
25 |
Correct |
1010 ms |
132460 KB |
Output is correct |
26 |
Correct |
1720 ms |
259512 KB |
Output is correct |
27 |
Correct |
2408 ms |
341852 KB |
Output is correct |
28 |
Correct |
3223 ms |
524288 KB |
Output is correct |
29 |
Correct |
1052 ms |
133868 KB |
Output is correct |
30 |
Correct |
1805 ms |
260524 KB |
Output is correct |
31 |
Correct |
2523 ms |
343016 KB |
Output is correct |
32 |
Correct |
3284 ms |
522456 KB |
Output is correct |
33 |
Correct |
1047 ms |
134288 KB |
Output is correct |
34 |
Correct |
1812 ms |
260728 KB |
Output is correct |
35 |
Correct |
2534 ms |
344732 KB |
Output is correct |
36 |
Correct |
3316 ms |
522964 KB |
Output is correct |
37 |
Correct |
1545 ms |
135344 KB |
Output is correct |
38 |
Correct |
2312 ms |
262672 KB |
Output is correct |
39 |
Correct |
2849 ms |
347476 KB |
Output is correct |
40 |
Correct |
3328 ms |
524288 KB |
Output is correct |
41 |
Correct |
1805 ms |
134372 KB |
Output is correct |
42 |
Correct |
2571 ms |
260756 KB |
Output is correct |
43 |
Correct |
3031 ms |
343308 KB |
Output is correct |
44 |
Correct |
3675 ms |
522888 KB |
Output is correct |
45 |
Correct |
1916 ms |
134768 KB |
Output is correct |
46 |
Correct |
2699 ms |
261352 KB |
Output is correct |
47 |
Correct |
3231 ms |
343472 KB |
Output is correct |
48 |
Correct |
3783 ms |
523336 KB |
Output is correct |