#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll L = 31;
const ll N = 2e5 + 50;
const ll M = 3e6 + 50;
const ll Mod = 1e9 + 7;
int n, q, sum[N], st[N], ft[N], timer = 1;
vector<int> adj[N];
vector<pair<char, pii>> qu;
void dfs(int v){
st[v] = timer++;
for(int u: adj[v]) dfs(u);
ft[v] = timer;
}
int trieInd = 1, child[M][2];
set<int> idx[M];
void add(int x){
int cur = 0;
for(int i = L-1; i >= 0; i--){
int th = sum[x] >> i & 1;
if(!child[cur][th]) child[cur][th] = trieInd++;
cur = child[cur][th]; idx[cur].insert(st[x]);
}
}
bool ok(int l, int r, int id){
auto y = idx[id].lower_bound(l);
return (y != idx[id].end() && (*y) < r);
}
int get(int x, int l, int r){
int cur = 0, ans = 0;
for(int i = L-1; i >= 0; i--){
int th = x >> i & 1;
if(child[cur][1-th] && ok(l, r, child[cur][1-th])){
ans += (1 << i); cur = child[cur][1-th];
}
else cur = child[cur][th];
}
return ans;
}
int main(){
fast_io;
cin >> q;
n = 1;
for(int i = 1; i <= q; i++){
string t; int a, b;
cin >> t >> a >> b;
if(t[0] == 'A'){
adj[a].pb(++n);
sum[n] = sum[a] ^ b;
}
qu.pb({t[0], {a, b}});
}
dfs(1);
int m = 1; add(1);
for(auto [t, e]: qu){
int a = e.F, b = e.S;
if(t == 'A') add(++m);
else cout << get(sum[a], st[b], ft[b]) << endl;
}
}
Compilation message
klasika.cpp: In function 'int main()':
klasika.cpp:92:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
92 | for(auto [t, e]: qu){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
148448 KB |
Output is correct |
2 |
Correct |
35 ms |
148308 KB |
Output is correct |
3 |
Correct |
33 ms |
148568 KB |
Output is correct |
4 |
Correct |
35 ms |
148572 KB |
Output is correct |
5 |
Correct |
34 ms |
148384 KB |
Output is correct |
6 |
Correct |
33 ms |
148304 KB |
Output is correct |
7 |
Correct |
33 ms |
148304 KB |
Output is correct |
8 |
Correct |
37 ms |
148572 KB |
Output is correct |
9 |
Correct |
34 ms |
148356 KB |
Output is correct |
10 |
Correct |
34 ms |
148504 KB |
Output is correct |
11 |
Correct |
34 ms |
148308 KB |
Output is correct |
12 |
Correct |
34 ms |
148608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
148448 KB |
Output is correct |
2 |
Correct |
35 ms |
148308 KB |
Output is correct |
3 |
Correct |
33 ms |
148568 KB |
Output is correct |
4 |
Correct |
35 ms |
148572 KB |
Output is correct |
5 |
Correct |
34 ms |
148384 KB |
Output is correct |
6 |
Correct |
33 ms |
148304 KB |
Output is correct |
7 |
Correct |
33 ms |
148304 KB |
Output is correct |
8 |
Correct |
37 ms |
148572 KB |
Output is correct |
9 |
Correct |
34 ms |
148356 KB |
Output is correct |
10 |
Correct |
34 ms |
148504 KB |
Output is correct |
11 |
Correct |
34 ms |
148308 KB |
Output is correct |
12 |
Correct |
34 ms |
148608 KB |
Output is correct |
13 |
Correct |
35 ms |
149084 KB |
Output is correct |
14 |
Correct |
37 ms |
149652 KB |
Output is correct |
15 |
Correct |
37 ms |
150116 KB |
Output is correct |
16 |
Correct |
38 ms |
150644 KB |
Output is correct |
17 |
Correct |
36 ms |
148820 KB |
Output is correct |
18 |
Correct |
36 ms |
149588 KB |
Output is correct |
19 |
Correct |
38 ms |
150108 KB |
Output is correct |
20 |
Correct |
44 ms |
150724 KB |
Output is correct |
21 |
Correct |
35 ms |
149028 KB |
Output is correct |
22 |
Correct |
40 ms |
149844 KB |
Output is correct |
23 |
Correct |
37 ms |
150004 KB |
Output is correct |
24 |
Correct |
41 ms |
150612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
537 ms |
220064 KB |
Output is correct |
2 |
Correct |
1088 ms |
285368 KB |
Output is correct |
3 |
Correct |
1526 ms |
349064 KB |
Output is correct |
4 |
Correct |
2019 ms |
414128 KB |
Output is correct |
5 |
Correct |
650 ms |
218588 KB |
Output is correct |
6 |
Correct |
1260 ms |
281996 KB |
Output is correct |
7 |
Correct |
1890 ms |
344196 KB |
Output is correct |
8 |
Correct |
2554 ms |
407396 KB |
Output is correct |
9 |
Correct |
650 ms |
218648 KB |
Output is correct |
10 |
Correct |
1244 ms |
283568 KB |
Output is correct |
11 |
Correct |
2214 ms |
346196 KB |
Output is correct |
12 |
Correct |
2813 ms |
409184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
148448 KB |
Output is correct |
2 |
Correct |
35 ms |
148308 KB |
Output is correct |
3 |
Correct |
33 ms |
148568 KB |
Output is correct |
4 |
Correct |
35 ms |
148572 KB |
Output is correct |
5 |
Correct |
34 ms |
148384 KB |
Output is correct |
6 |
Correct |
33 ms |
148304 KB |
Output is correct |
7 |
Correct |
33 ms |
148304 KB |
Output is correct |
8 |
Correct |
37 ms |
148572 KB |
Output is correct |
9 |
Correct |
34 ms |
148356 KB |
Output is correct |
10 |
Correct |
34 ms |
148504 KB |
Output is correct |
11 |
Correct |
34 ms |
148308 KB |
Output is correct |
12 |
Correct |
34 ms |
148608 KB |
Output is correct |
13 |
Correct |
35 ms |
149084 KB |
Output is correct |
14 |
Correct |
37 ms |
149652 KB |
Output is correct |
15 |
Correct |
37 ms |
150116 KB |
Output is correct |
16 |
Correct |
38 ms |
150644 KB |
Output is correct |
17 |
Correct |
36 ms |
148820 KB |
Output is correct |
18 |
Correct |
36 ms |
149588 KB |
Output is correct |
19 |
Correct |
38 ms |
150108 KB |
Output is correct |
20 |
Correct |
44 ms |
150724 KB |
Output is correct |
21 |
Correct |
35 ms |
149028 KB |
Output is correct |
22 |
Correct |
40 ms |
149844 KB |
Output is correct |
23 |
Correct |
37 ms |
150004 KB |
Output is correct |
24 |
Correct |
41 ms |
150612 KB |
Output is correct |
25 |
Correct |
537 ms |
220064 KB |
Output is correct |
26 |
Correct |
1088 ms |
285368 KB |
Output is correct |
27 |
Correct |
1526 ms |
349064 KB |
Output is correct |
28 |
Correct |
2019 ms |
414128 KB |
Output is correct |
29 |
Correct |
650 ms |
218588 KB |
Output is correct |
30 |
Correct |
1260 ms |
281996 KB |
Output is correct |
31 |
Correct |
1890 ms |
344196 KB |
Output is correct |
32 |
Correct |
2554 ms |
407396 KB |
Output is correct |
33 |
Correct |
650 ms |
218648 KB |
Output is correct |
34 |
Correct |
1244 ms |
283568 KB |
Output is correct |
35 |
Correct |
2214 ms |
346196 KB |
Output is correct |
36 |
Correct |
2813 ms |
409184 KB |
Output is correct |
37 |
Correct |
1434 ms |
220704 KB |
Output is correct |
38 |
Correct |
2005 ms |
285364 KB |
Output is correct |
39 |
Correct |
2395 ms |
350980 KB |
Output is correct |
40 |
Correct |
2473 ms |
414532 KB |
Output is correct |
41 |
Correct |
1266 ms |
218584 KB |
Output is correct |
42 |
Correct |
1906 ms |
281928 KB |
Output is correct |
43 |
Correct |
2571 ms |
345028 KB |
Output is correct |
44 |
Correct |
2853 ms |
407032 KB |
Output is correct |
45 |
Correct |
1261 ms |
218848 KB |
Output is correct |
46 |
Correct |
1951 ms |
282892 KB |
Output is correct |
47 |
Correct |
2379 ms |
345392 KB |
Output is correct |
48 |
Correct |
2522 ms |
409016 KB |
Output is correct |