#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int q, x, y, dp[nx], cur=1, t[nx], res[nx], sz[nx];
string s;
vector<int> d[nx];
vector<pair<int, int>> qrs[nx];
struct node
{
int mn;
node *l, *r;
node(): mn(1e9), l(0), r(0){}
};
typedef node* pnode;
pnode rt[nx];
void add(int x, int u)
{
if (!rt[x]) rt[x]=new node(), rt[x]->mn=0;
pnode c=rt[x];
for (int i=30; i>=0; i--)
{
if (dp[u]&(1<<i))
{
if (!c->r) c->r=new node();
c=c->r;
c->mn=min(c->mn, t[u]);
}
else
{
if (!c->l) c->l=new node();
c=c->l;
c->mn=min(c->mn, t[u]);
}
}
}
void dfsadd(int u, int p)
{
add(p, u);
for (auto v:d[u]) dfsadd(v, p);
}
void dfsdelete(pnode x)
{
if (!x) return;
dfsdelete(x->l);
dfsdelete(x->r);
delete x;
}
void solve(int u)
{
sz[u]=1;
pair<int, int> hv;
for (auto v:d[u]) solve(v), sz[u]+=sz[v], hv=max(hv, {sz[v], v});
if (hv.second) swap(rt[u], rt[hv.second]);
for (auto v:d[u]) if (v!=hv.second) dfsdelete(rt[v]), dfsadd(v, u);
add(u, u);
for (auto [x, idx]:qrs[u])
{
int ans=0;
pnode cur=rt[u];
for (int i=0; i<=30; i++)
{
if (dp[x]&(1<<(30-i)))
{
if (cur->l&&cur->l->mn<=idx) ans+=(1<<(30-i)), cur=cur->l;
else cur=cur->r;
}
else
{
if (cur->r&&cur->r->mn<=idx) ans+=(1<<(30-i)), cur=cur->r;
else cur=cur->l;
}
}
res[idx]=ans;
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>q;
for (int i=1; i<=q; i++)
{
cin>>s>>x>>y;
res[i]=-1;
if (s[0]=='A') dp[++cur]=dp[x]^y, d[x].push_back(cur), t[cur]=i;
else qrs[y].push_back({x, i});
}
solve(1);
for (int i=1; i<=q; i++) if (res[i]!=-1) cout<<res[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12624 KB |
Output is correct |
2 |
Correct |
4 ms |
11344 KB |
Output is correct |
3 |
Correct |
4 ms |
11360 KB |
Output is correct |
4 |
Correct |
6 ms |
11416 KB |
Output is correct |
5 |
Correct |
8 ms |
11344 KB |
Output is correct |
6 |
Correct |
7 ms |
11344 KB |
Output is correct |
7 |
Correct |
7 ms |
11344 KB |
Output is correct |
8 |
Correct |
5 ms |
11344 KB |
Output is correct |
9 |
Correct |
4 ms |
12624 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11344 KB |
Output is correct |
12 |
Correct |
4 ms |
12880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12624 KB |
Output is correct |
2 |
Correct |
4 ms |
11344 KB |
Output is correct |
3 |
Correct |
4 ms |
11360 KB |
Output is correct |
4 |
Correct |
6 ms |
11416 KB |
Output is correct |
5 |
Correct |
8 ms |
11344 KB |
Output is correct |
6 |
Correct |
7 ms |
11344 KB |
Output is correct |
7 |
Correct |
7 ms |
11344 KB |
Output is correct |
8 |
Correct |
5 ms |
11344 KB |
Output is correct |
9 |
Correct |
4 ms |
12624 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11344 KB |
Output is correct |
12 |
Correct |
4 ms |
12880 KB |
Output is correct |
13 |
Correct |
4 ms |
13136 KB |
Output is correct |
14 |
Correct |
5 ms |
13392 KB |
Output is correct |
15 |
Correct |
7 ms |
12344 KB |
Output is correct |
16 |
Correct |
7 ms |
13904 KB |
Output is correct |
17 |
Correct |
6 ms |
13136 KB |
Output is correct |
18 |
Correct |
7 ms |
13340 KB |
Output is correct |
19 |
Correct |
8 ms |
13816 KB |
Output is correct |
20 |
Correct |
10 ms |
13904 KB |
Output is correct |
21 |
Correct |
7 ms |
13136 KB |
Output is correct |
22 |
Correct |
7 ms |
13392 KB |
Output is correct |
23 |
Correct |
9 ms |
13648 KB |
Output is correct |
24 |
Correct |
7 ms |
13924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
44644 KB |
Output is correct |
2 |
Correct |
180 ms |
65408 KB |
Output is correct |
3 |
Correct |
229 ms |
89456 KB |
Output is correct |
4 |
Correct |
241 ms |
108992 KB |
Output is correct |
5 |
Correct |
339 ms |
37632 KB |
Output is correct |
6 |
Correct |
604 ms |
59836 KB |
Output is correct |
7 |
Correct |
841 ms |
75576 KB |
Output is correct |
8 |
Correct |
1195 ms |
93696 KB |
Output is correct |
9 |
Correct |
221 ms |
39952 KB |
Output is correct |
10 |
Correct |
307 ms |
58560 KB |
Output is correct |
11 |
Correct |
382 ms |
76988 KB |
Output is correct |
12 |
Correct |
431 ms |
94168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12624 KB |
Output is correct |
2 |
Correct |
4 ms |
11344 KB |
Output is correct |
3 |
Correct |
4 ms |
11360 KB |
Output is correct |
4 |
Correct |
6 ms |
11416 KB |
Output is correct |
5 |
Correct |
8 ms |
11344 KB |
Output is correct |
6 |
Correct |
7 ms |
11344 KB |
Output is correct |
7 |
Correct |
7 ms |
11344 KB |
Output is correct |
8 |
Correct |
5 ms |
11344 KB |
Output is correct |
9 |
Correct |
4 ms |
12624 KB |
Output is correct |
10 |
Correct |
4 ms |
11344 KB |
Output is correct |
11 |
Correct |
5 ms |
11344 KB |
Output is correct |
12 |
Correct |
4 ms |
12880 KB |
Output is correct |
13 |
Correct |
4 ms |
13136 KB |
Output is correct |
14 |
Correct |
5 ms |
13392 KB |
Output is correct |
15 |
Correct |
7 ms |
12344 KB |
Output is correct |
16 |
Correct |
7 ms |
13904 KB |
Output is correct |
17 |
Correct |
6 ms |
13136 KB |
Output is correct |
18 |
Correct |
7 ms |
13340 KB |
Output is correct |
19 |
Correct |
8 ms |
13816 KB |
Output is correct |
20 |
Correct |
10 ms |
13904 KB |
Output is correct |
21 |
Correct |
7 ms |
13136 KB |
Output is correct |
22 |
Correct |
7 ms |
13392 KB |
Output is correct |
23 |
Correct |
9 ms |
13648 KB |
Output is correct |
24 |
Correct |
7 ms |
13924 KB |
Output is correct |
25 |
Correct |
150 ms |
44644 KB |
Output is correct |
26 |
Correct |
180 ms |
65408 KB |
Output is correct |
27 |
Correct |
229 ms |
89456 KB |
Output is correct |
28 |
Correct |
241 ms |
108992 KB |
Output is correct |
29 |
Correct |
339 ms |
37632 KB |
Output is correct |
30 |
Correct |
604 ms |
59836 KB |
Output is correct |
31 |
Correct |
841 ms |
75576 KB |
Output is correct |
32 |
Correct |
1195 ms |
93696 KB |
Output is correct |
33 |
Correct |
221 ms |
39952 KB |
Output is correct |
34 |
Correct |
307 ms |
58560 KB |
Output is correct |
35 |
Correct |
382 ms |
76988 KB |
Output is correct |
36 |
Correct |
431 ms |
94168 KB |
Output is correct |
37 |
Correct |
155 ms |
46664 KB |
Output is correct |
38 |
Correct |
202 ms |
68936 KB |
Output is correct |
39 |
Correct |
227 ms |
91976 KB |
Output is correct |
40 |
Correct |
259 ms |
113228 KB |
Output is correct |
41 |
Correct |
313 ms |
41800 KB |
Output is correct |
42 |
Correct |
588 ms |
64184 KB |
Output is correct |
43 |
Correct |
865 ms |
79688 KB |
Output is correct |
44 |
Correct |
1185 ms |
96604 KB |
Output is correct |
45 |
Correct |
186 ms |
40304 KB |
Output is correct |
46 |
Correct |
257 ms |
59944 KB |
Output is correct |
47 |
Correct |
362 ms |
77896 KB |
Output is correct |
48 |
Correct |
442 ms |
95260 KB |
Output is correct |