#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=2e5;
const int L=30;
struct Trie
{
int mn_time;
Trie *e[2];
};
const int TRIE_SIZE=N*(L+1)+10;
Trie triemem[TRIE_SIZE];
int trieit=0;
Trie* newtrie()
{
return &triemem[trieit++];
}
int getmn_time(Trie* x)
{
return (x==nullptr ? N+10:x->mn_time);
}
Trie* build(int c,int t,int l)
{
Trie* rt=newtrie();
rt->mn_time=t;
if(l<0)
return rt;
bool tmp=(c&(1<<l));
//cerr<<tmp<<" "<<c<<"\n";
rt->e[tmp]=build(c,t,l-1);
return rt;
}
Trie* merge(Trie* x,Trie* y)
{
if(x==nullptr)
return y;
if(y==nullptr)
return x;
x->mn_time=min(x->mn_time,y->mn_time);
for(int i:{0,1})
{
//cerr<<i<<" "<<getmn_time(x->e[i])<<" "<<getmn_time(y->e[i])<<"\n";
x->e[i]=merge(x->e[i],y->e[i]);
}
return x;
}
int read(Trie* x,int c,int t,int l)
{
if(l==-1)
return c;
bool tmp=(c&(1<<l));
//cerr<<c<<" "<<t<<" "<<l<<" "<<tmp<<"\n";
c|=(1<<l);
if(getmn_time(x->e[!tmp])<t)
return read(x->e[!tmp],c,t,l-1);
c^=(1<<l);
return read(x->e[tmp],c,t,l-1);
}
vector<pair<int,int>> que[N+10];
int tim[N+10];
vector<int> e[N+10];
int d[N+10];
int ans[N+10];
bool is_query[N+10];
Trie* dfs(int x)
{
Trie* rt=build(d[x],tim[x],L);
for(auto v:e[x])
{
auto tmp=dfs(v);
rt=merge(rt,tmp);
}
for(auto [t,c]:que[x])
ans[t]=read(rt,c,t,L);
return rt;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int q,n=1;
cin>>q;
for(int i=1;i<=q;i++)
{
string t;
int a,b;
cin>>t>>a>>b;
if(t=="Add")
{
e[a].push_back(++n);
d[n]=d[a]^b;
tim[n]=i;
}
else
{
is_query[i]=true;
que[b].emplace_back(i,d[a]);
}
}
dfs(1);
for(int i=1;i<=q;i++)
{
if(is_query[i])
cout<<ans[i]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9804 KB |
Output is correct |
3 |
Correct |
7 ms |
9804 KB |
Output is correct |
4 |
Correct |
6 ms |
9804 KB |
Output is correct |
5 |
Correct |
6 ms |
9676 KB |
Output is correct |
6 |
Correct |
7 ms |
9724 KB |
Output is correct |
7 |
Correct |
6 ms |
9724 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9732 KB |
Output is correct |
11 |
Correct |
6 ms |
9804 KB |
Output is correct |
12 |
Correct |
7 ms |
9780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9804 KB |
Output is correct |
3 |
Correct |
7 ms |
9804 KB |
Output is correct |
4 |
Correct |
6 ms |
9804 KB |
Output is correct |
5 |
Correct |
6 ms |
9676 KB |
Output is correct |
6 |
Correct |
7 ms |
9724 KB |
Output is correct |
7 |
Correct |
6 ms |
9724 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9732 KB |
Output is correct |
11 |
Correct |
6 ms |
9804 KB |
Output is correct |
12 |
Correct |
7 ms |
9780 KB |
Output is correct |
13 |
Correct |
8 ms |
10072 KB |
Output is correct |
14 |
Correct |
8 ms |
10480 KB |
Output is correct |
15 |
Correct |
9 ms |
10828 KB |
Output is correct |
16 |
Correct |
9 ms |
11212 KB |
Output is correct |
17 |
Correct |
8 ms |
10060 KB |
Output is correct |
18 |
Correct |
8 ms |
10316 KB |
Output is correct |
19 |
Correct |
8 ms |
10700 KB |
Output is correct |
20 |
Correct |
9 ms |
10956 KB |
Output is correct |
21 |
Correct |
9 ms |
10060 KB |
Output is correct |
22 |
Correct |
8 ms |
10444 KB |
Output is correct |
23 |
Correct |
8 ms |
10768 KB |
Output is correct |
24 |
Correct |
9 ms |
10944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
205 ms |
48812 KB |
Output is correct |
2 |
Correct |
268 ms |
87008 KB |
Output is correct |
3 |
Correct |
293 ms |
121228 KB |
Output is correct |
4 |
Correct |
333 ms |
156420 KB |
Output is correct |
5 |
Correct |
211 ms |
47428 KB |
Output is correct |
6 |
Correct |
261 ms |
78228 KB |
Output is correct |
7 |
Correct |
322 ms |
108496 KB |
Output is correct |
8 |
Correct |
364 ms |
139124 KB |
Output is correct |
9 |
Correct |
203 ms |
48128 KB |
Output is correct |
10 |
Correct |
265 ms |
79832 KB |
Output is correct |
11 |
Correct |
287 ms |
111392 KB |
Output is correct |
12 |
Correct |
307 ms |
142484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9804 KB |
Output is correct |
3 |
Correct |
7 ms |
9804 KB |
Output is correct |
4 |
Correct |
6 ms |
9804 KB |
Output is correct |
5 |
Correct |
6 ms |
9676 KB |
Output is correct |
6 |
Correct |
7 ms |
9724 KB |
Output is correct |
7 |
Correct |
6 ms |
9724 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9732 KB |
Output is correct |
11 |
Correct |
6 ms |
9804 KB |
Output is correct |
12 |
Correct |
7 ms |
9780 KB |
Output is correct |
13 |
Correct |
8 ms |
10072 KB |
Output is correct |
14 |
Correct |
8 ms |
10480 KB |
Output is correct |
15 |
Correct |
9 ms |
10828 KB |
Output is correct |
16 |
Correct |
9 ms |
11212 KB |
Output is correct |
17 |
Correct |
8 ms |
10060 KB |
Output is correct |
18 |
Correct |
8 ms |
10316 KB |
Output is correct |
19 |
Correct |
8 ms |
10700 KB |
Output is correct |
20 |
Correct |
9 ms |
10956 KB |
Output is correct |
21 |
Correct |
9 ms |
10060 KB |
Output is correct |
22 |
Correct |
8 ms |
10444 KB |
Output is correct |
23 |
Correct |
8 ms |
10768 KB |
Output is correct |
24 |
Correct |
9 ms |
10944 KB |
Output is correct |
25 |
Correct |
205 ms |
48812 KB |
Output is correct |
26 |
Correct |
268 ms |
87008 KB |
Output is correct |
27 |
Correct |
293 ms |
121228 KB |
Output is correct |
28 |
Correct |
333 ms |
156420 KB |
Output is correct |
29 |
Correct |
211 ms |
47428 KB |
Output is correct |
30 |
Correct |
261 ms |
78228 KB |
Output is correct |
31 |
Correct |
322 ms |
108496 KB |
Output is correct |
32 |
Correct |
364 ms |
139124 KB |
Output is correct |
33 |
Correct |
203 ms |
48128 KB |
Output is correct |
34 |
Correct |
265 ms |
79832 KB |
Output is correct |
35 |
Correct |
287 ms |
111392 KB |
Output is correct |
36 |
Correct |
307 ms |
142484 KB |
Output is correct |
37 |
Correct |
241 ms |
53348 KB |
Output is correct |
38 |
Correct |
317 ms |
88104 KB |
Output is correct |
39 |
Correct |
308 ms |
123328 KB |
Output is correct |
40 |
Correct |
356 ms |
157288 KB |
Output is correct |
41 |
Correct |
201 ms |
48764 KB |
Output is correct |
42 |
Correct |
260 ms |
79504 KB |
Output is correct |
43 |
Correct |
324 ms |
109600 KB |
Output is correct |
44 |
Correct |
350 ms |
139832 KB |
Output is correct |
45 |
Correct |
197 ms |
49348 KB |
Output is correct |
46 |
Correct |
237 ms |
81284 KB |
Output is correct |
47 |
Correct |
286 ms |
112176 KB |
Output is correct |
48 |
Correct |
308 ms |
143260 KB |
Output is correct |