# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889382 |
2023-12-19T15:34:02 Z |
Alish |
Klasika (COCI20_klasika) |
C++17 |
|
1360 ms |
524288 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
ll mod = 1e9+7 ;
const int N = 2e5+23, L=31;
ll h[N];
int ch[N*L][2];
set<int> ss[N*L];
int st[N], ft[N], tim=0;
vector<int> g[N];
vector<pair<int, pii> > Q;
int cnt=1;
int tr;
void dfs(int v){
st[v]=tim++;
for (int u: g[v]) dfs(u);
ft[v]=tim;
}
void add(int x, int pp){
int cur=0;
for (int i=L-1; i>=0; i--){
int t=(x>>i&1);
if(!ch[cur][t]) ch[cur][t]=++tr;
cur=ch[cur][t];
ss[cur].insert(pp);
}
}
int get(int x, int v){
int cur=0;
int ans=0;
for (int i=L-1; i>=0; i--){
int t=(x>>i&1);
t=1-t;
if(ch[cur][t]){
auto x=ss[ch[cur][t]].lower_bound(st[v]);
if(x==ss[ch[cur][t]].end() || *x>=ft[v]){
cur=ch[cur][1-t];
}
else{
ans+=(1<<i);
cur=ch[cur][t];
}
}
else{
cur=ch[cur][1-t];
}
}
return ans;
}
int main()
{
fast_io
int q; cin>>q;
for (int i=0; i<q; i++){
string s; cin>>s;
if(s=="Add"){
ll u, w;
cin>>u>>w;
cnt++;
h[cnt]=h[u]^w;
g[u].pb(cnt);
Q.pb({0, {cnt, u}});
}
else{
int u, v; cin>>v>>u;
Q.pb({1, {v, u}});
}
}
dfs(1);
add(0, st[1]);
for (auto pp: Q){
int t=pp.F, v=pp.S.F, u=pp.S.S;
if(!t){
add(h[v], st[v]);
}
else{
cout<<get(h[v], u)<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
298152 KB |
Output is correct |
2 |
Correct |
57 ms |
298172 KB |
Output is correct |
3 |
Correct |
57 ms |
298196 KB |
Output is correct |
4 |
Correct |
57 ms |
298292 KB |
Output is correct |
5 |
Correct |
63 ms |
298040 KB |
Output is correct |
6 |
Correct |
58 ms |
298148 KB |
Output is correct |
7 |
Correct |
59 ms |
298324 KB |
Output is correct |
8 |
Correct |
58 ms |
298324 KB |
Output is correct |
9 |
Correct |
58 ms |
298188 KB |
Output is correct |
10 |
Correct |
59 ms |
298280 KB |
Output is correct |
11 |
Correct |
57 ms |
298324 KB |
Output is correct |
12 |
Correct |
59 ms |
298576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
298152 KB |
Output is correct |
2 |
Correct |
57 ms |
298172 KB |
Output is correct |
3 |
Correct |
57 ms |
298196 KB |
Output is correct |
4 |
Correct |
57 ms |
298292 KB |
Output is correct |
5 |
Correct |
63 ms |
298040 KB |
Output is correct |
6 |
Correct |
58 ms |
298148 KB |
Output is correct |
7 |
Correct |
59 ms |
298324 KB |
Output is correct |
8 |
Correct |
58 ms |
298324 KB |
Output is correct |
9 |
Correct |
58 ms |
298188 KB |
Output is correct |
10 |
Correct |
59 ms |
298280 KB |
Output is correct |
11 |
Correct |
57 ms |
298324 KB |
Output is correct |
12 |
Correct |
59 ms |
298576 KB |
Output is correct |
13 |
Correct |
61 ms |
298832 KB |
Output is correct |
14 |
Correct |
60 ms |
299484 KB |
Output is correct |
15 |
Correct |
61 ms |
299860 KB |
Output is correct |
16 |
Correct |
62 ms |
300648 KB |
Output is correct |
17 |
Correct |
59 ms |
298580 KB |
Output is correct |
18 |
Correct |
61 ms |
299264 KB |
Output is correct |
19 |
Correct |
69 ms |
299976 KB |
Output is correct |
20 |
Correct |
64 ms |
300528 KB |
Output is correct |
21 |
Correct |
59 ms |
298812 KB |
Output is correct |
22 |
Correct |
61 ms |
299184 KB |
Output is correct |
23 |
Correct |
64 ms |
300112 KB |
Output is correct |
24 |
Correct |
63 ms |
300372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
520 ms |
370200 KB |
Output is correct |
2 |
Correct |
967 ms |
435504 KB |
Output is correct |
3 |
Correct |
1360 ms |
499680 KB |
Output is correct |
4 |
Runtime error |
1193 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
298152 KB |
Output is correct |
2 |
Correct |
57 ms |
298172 KB |
Output is correct |
3 |
Correct |
57 ms |
298196 KB |
Output is correct |
4 |
Correct |
57 ms |
298292 KB |
Output is correct |
5 |
Correct |
63 ms |
298040 KB |
Output is correct |
6 |
Correct |
58 ms |
298148 KB |
Output is correct |
7 |
Correct |
59 ms |
298324 KB |
Output is correct |
8 |
Correct |
58 ms |
298324 KB |
Output is correct |
9 |
Correct |
58 ms |
298188 KB |
Output is correct |
10 |
Correct |
59 ms |
298280 KB |
Output is correct |
11 |
Correct |
57 ms |
298324 KB |
Output is correct |
12 |
Correct |
59 ms |
298576 KB |
Output is correct |
13 |
Correct |
61 ms |
298832 KB |
Output is correct |
14 |
Correct |
60 ms |
299484 KB |
Output is correct |
15 |
Correct |
61 ms |
299860 KB |
Output is correct |
16 |
Correct |
62 ms |
300648 KB |
Output is correct |
17 |
Correct |
59 ms |
298580 KB |
Output is correct |
18 |
Correct |
61 ms |
299264 KB |
Output is correct |
19 |
Correct |
69 ms |
299976 KB |
Output is correct |
20 |
Correct |
64 ms |
300528 KB |
Output is correct |
21 |
Correct |
59 ms |
298812 KB |
Output is correct |
22 |
Correct |
61 ms |
299184 KB |
Output is correct |
23 |
Correct |
64 ms |
300112 KB |
Output is correct |
24 |
Correct |
63 ms |
300372 KB |
Output is correct |
25 |
Correct |
520 ms |
370200 KB |
Output is correct |
26 |
Correct |
967 ms |
435504 KB |
Output is correct |
27 |
Correct |
1360 ms |
499680 KB |
Output is correct |
28 |
Runtime error |
1193 ms |
524288 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |