#include <bits/stdc++.h>
using namespace std;
const int nx=4e5+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 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) 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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20048 KB |
Output is correct |
2 |
Correct |
12 ms |
20008 KB |
Output is correct |
3 |
Correct |
12 ms |
20216 KB |
Output is correct |
4 |
Correct |
12 ms |
20048 KB |
Output is correct |
5 |
Correct |
12 ms |
20216 KB |
Output is correct |
6 |
Correct |
13 ms |
20236 KB |
Output is correct |
7 |
Correct |
11 ms |
21244 KB |
Output is correct |
8 |
Correct |
11 ms |
20320 KB |
Output is correct |
9 |
Correct |
12 ms |
20040 KB |
Output is correct |
10 |
Correct |
14 ms |
20048 KB |
Output is correct |
11 |
Correct |
14 ms |
20304 KB |
Output is correct |
12 |
Correct |
14 ms |
20304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20048 KB |
Output is correct |
2 |
Correct |
12 ms |
20008 KB |
Output is correct |
3 |
Correct |
12 ms |
20216 KB |
Output is correct |
4 |
Correct |
12 ms |
20048 KB |
Output is correct |
5 |
Correct |
12 ms |
20216 KB |
Output is correct |
6 |
Correct |
13 ms |
20236 KB |
Output is correct |
7 |
Correct |
11 ms |
21244 KB |
Output is correct |
8 |
Correct |
11 ms |
20320 KB |
Output is correct |
9 |
Correct |
12 ms |
20040 KB |
Output is correct |
10 |
Correct |
14 ms |
20048 KB |
Output is correct |
11 |
Correct |
14 ms |
20304 KB |
Output is correct |
12 |
Correct |
14 ms |
20304 KB |
Output is correct |
13 |
Correct |
13 ms |
20364 KB |
Output is correct |
14 |
Correct |
13 ms |
20816 KB |
Output is correct |
15 |
Correct |
12 ms |
21004 KB |
Output is correct |
16 |
Correct |
12 ms |
21196 KB |
Output is correct |
17 |
Correct |
12 ms |
20972 KB |
Output is correct |
18 |
Correct |
14 ms |
22096 KB |
Output is correct |
19 |
Correct |
16 ms |
23428 KB |
Output is correct |
20 |
Correct |
17 ms |
24400 KB |
Output is correct |
21 |
Correct |
13 ms |
20816 KB |
Output is correct |
22 |
Correct |
16 ms |
21584 KB |
Output is correct |
23 |
Correct |
16 ms |
22172 KB |
Output is correct |
24 |
Correct |
15 ms |
22864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
51648 KB |
Output is correct |
2 |
Correct |
179 ms |
74356 KB |
Output is correct |
3 |
Correct |
190 ms |
95676 KB |
Output is correct |
4 |
Correct |
223 ms |
116928 KB |
Output is correct |
5 |
Correct |
305 ms |
161772 KB |
Output is correct |
6 |
Correct |
595 ms |
304772 KB |
Output is correct |
7 |
Correct |
785 ms |
443656 KB |
Output is correct |
8 |
Runtime error |
906 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20048 KB |
Output is correct |
2 |
Correct |
12 ms |
20008 KB |
Output is correct |
3 |
Correct |
12 ms |
20216 KB |
Output is correct |
4 |
Correct |
12 ms |
20048 KB |
Output is correct |
5 |
Correct |
12 ms |
20216 KB |
Output is correct |
6 |
Correct |
13 ms |
20236 KB |
Output is correct |
7 |
Correct |
11 ms |
21244 KB |
Output is correct |
8 |
Correct |
11 ms |
20320 KB |
Output is correct |
9 |
Correct |
12 ms |
20040 KB |
Output is correct |
10 |
Correct |
14 ms |
20048 KB |
Output is correct |
11 |
Correct |
14 ms |
20304 KB |
Output is correct |
12 |
Correct |
14 ms |
20304 KB |
Output is correct |
13 |
Correct |
13 ms |
20364 KB |
Output is correct |
14 |
Correct |
13 ms |
20816 KB |
Output is correct |
15 |
Correct |
12 ms |
21004 KB |
Output is correct |
16 |
Correct |
12 ms |
21196 KB |
Output is correct |
17 |
Correct |
12 ms |
20972 KB |
Output is correct |
18 |
Correct |
14 ms |
22096 KB |
Output is correct |
19 |
Correct |
16 ms |
23428 KB |
Output is correct |
20 |
Correct |
17 ms |
24400 KB |
Output is correct |
21 |
Correct |
13 ms |
20816 KB |
Output is correct |
22 |
Correct |
16 ms |
21584 KB |
Output is correct |
23 |
Correct |
16 ms |
22172 KB |
Output is correct |
24 |
Correct |
15 ms |
22864 KB |
Output is correct |
25 |
Correct |
144 ms |
51648 KB |
Output is correct |
26 |
Correct |
179 ms |
74356 KB |
Output is correct |
27 |
Correct |
190 ms |
95676 KB |
Output is correct |
28 |
Correct |
223 ms |
116928 KB |
Output is correct |
29 |
Correct |
305 ms |
161772 KB |
Output is correct |
30 |
Correct |
595 ms |
304772 KB |
Output is correct |
31 |
Correct |
785 ms |
443656 KB |
Output is correct |
32 |
Runtime error |
906 ms |
524288 KB |
Execution killed with signal 9 |
33 |
Halted |
0 ms |
0 KB |
- |