# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
520269 |
2022-01-29T04:39:15 Z |
AkiYuu |
Klasika (COCI20_klasika) |
C++17 |
|
2560 ms |
476808 KB |
/*
Problems:
Author: AkiYuu
*/
#include <bits/stdc++.h>
#define task "GROUP"
#define ll long long
#define ld long double
#define pb push_back
#define ffw(i,a,b) for (ll i = a; i <= b; i++)
#define fbw(i,b,a) for (ll i = b; i >= a; i--)
#define adj(v,adj,u) for (auto v : adj[u])
#define rep(i,a) for (auto i : a)
#define reset(a) memset(a, 0, sizeof(a))
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
using namespace std;
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
}
const int mxn = 1e6 + 5;
typedef pair<ll, ll> ii;
vector < vector < int > > op;
int q;
int tin[mxn], tout[mxn], xored[mxn], timer;
int trie[30 * 200005][2], dem;
vector < set<int> > TinBag;
vector < int > a[mxn];
void dfs(int u){
tin[u] = ++timer;
adj(v,a,u) dfs(v);
tout[u] = ++timer;
}
void add(int u, ll s){
int node = 0;
// cout << "ADD: ";
fbw(i,29,0){
int x = ( s & ( 1 << i) )> 0;
// cout << x;
if ( trie[node][x] == 0 ){
trie[node][x] = ++dem;
TinBag.pb( set<int>() );
}
node = trie[node][x];
TinBag[node].insert( tin[u] );
}
// cout << '\n';
}
ll getmax(int u , ll s){
int node = 0;
fbw(i,29,0){
int x = (s & (1 << i) ) > 0;
bool issub = 0;
int nxt = trie[node][x ^ 1];
if ( trie[node][x ^ 1] ){
auto pos = TinBag[ nxt ].lower_bound(tin[u]);
if ( pos != TinBag[ nxt ].end() && *pos <= tout[u] ) issub = 1;
else issub = 0;
}
if ( issub ) {
s ^= ( (x ^ 1) << i);
node = trie[ node ][ x ^ 1];
} else {
s ^= (x << i);
node = trie[ node ][x];
}
}
return s;
}
void solve(){
cin >> q;
int curnode = 1;
ffw(i,1,q){
string type;
ll u , v;
cin >> type >> u >> v;
if ( type == "Add") {
a[u].pb(++curnode);
xored[curnode] = xored[u] ^ v;
op.pb({0,curnode,xored[curnode]});
} else {
op.pb({1,u,v});
}
}
TinBag.pb( set<int>() );
dfs(1);
add(1, xored[1]);
for ( auto i : op){
if ( i[0] == 0)
add(i[1], i[2]);
else
cout << getmax(i[2], xored[ i[1] ]) << '\n';
}
}
int main(){
fastio();
int t = 1;
// cin >> t;
while (t--)
solve();
}
Compilation message
klasika.cpp: In function 'void solve()':
klasika.cpp:101:22: warning: narrowing conversion of 'u' from 'long long int' to 'int' [-Wnarrowing]
101 | op.pb({1,u,v});
| ^
klasika.cpp:101:22: warning: narrowing conversion of 'u' from 'long long int' to 'int' [-Wnarrowing]
klasika.cpp:101:24: warning: narrowing conversion of 'v' from 'long long int' to 'int' [-Wnarrowing]
101 | op.pb({1,u,v});
| ^
klasika.cpp:101:24: warning: narrowing conversion of 'v' from 'long long int' to 'int' [-Wnarrowing]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23936 KB |
Output is correct |
2 |
Correct |
12 ms |
24040 KB |
Output is correct |
3 |
Correct |
12 ms |
24192 KB |
Output is correct |
4 |
Correct |
12 ms |
24184 KB |
Output is correct |
5 |
Correct |
12 ms |
23932 KB |
Output is correct |
6 |
Correct |
12 ms |
24016 KB |
Output is correct |
7 |
Correct |
13 ms |
24192 KB |
Output is correct |
8 |
Correct |
12 ms |
24272 KB |
Output is correct |
9 |
Correct |
12 ms |
23988 KB |
Output is correct |
10 |
Correct |
13 ms |
24184 KB |
Output is correct |
11 |
Correct |
13 ms |
24140 KB |
Output is correct |
12 |
Correct |
14 ms |
24172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23936 KB |
Output is correct |
2 |
Correct |
12 ms |
24040 KB |
Output is correct |
3 |
Correct |
12 ms |
24192 KB |
Output is correct |
4 |
Correct |
12 ms |
24184 KB |
Output is correct |
5 |
Correct |
12 ms |
23932 KB |
Output is correct |
6 |
Correct |
12 ms |
24016 KB |
Output is correct |
7 |
Correct |
13 ms |
24192 KB |
Output is correct |
8 |
Correct |
12 ms |
24272 KB |
Output is correct |
9 |
Correct |
12 ms |
23988 KB |
Output is correct |
10 |
Correct |
13 ms |
24184 KB |
Output is correct |
11 |
Correct |
13 ms |
24140 KB |
Output is correct |
12 |
Correct |
14 ms |
24172 KB |
Output is correct |
13 |
Correct |
15 ms |
25284 KB |
Output is correct |
14 |
Correct |
17 ms |
26748 KB |
Output is correct |
15 |
Correct |
18 ms |
27116 KB |
Output is correct |
16 |
Correct |
21 ms |
29656 KB |
Output is correct |
17 |
Correct |
16 ms |
25352 KB |
Output is correct |
18 |
Correct |
21 ms |
26756 KB |
Output is correct |
19 |
Correct |
23 ms |
27068 KB |
Output is correct |
20 |
Correct |
20 ms |
27964 KB |
Output is correct |
21 |
Correct |
16 ms |
25280 KB |
Output is correct |
22 |
Correct |
17 ms |
26668 KB |
Output is correct |
23 |
Correct |
18 ms |
27068 KB |
Output is correct |
24 |
Correct |
20 ms |
27980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
637 ms |
141180 KB |
Output is correct |
2 |
Correct |
1169 ms |
249992 KB |
Output is correct |
3 |
Correct |
1646 ms |
309412 KB |
Output is correct |
4 |
Correct |
2098 ms |
476720 KB |
Output is correct |
5 |
Correct |
698 ms |
139244 KB |
Output is correct |
6 |
Correct |
1247 ms |
246344 KB |
Output is correct |
7 |
Correct |
1722 ms |
304636 KB |
Output is correct |
8 |
Correct |
2296 ms |
469232 KB |
Output is correct |
9 |
Correct |
682 ms |
139700 KB |
Output is correct |
10 |
Correct |
1182 ms |
247180 KB |
Output is correct |
11 |
Correct |
1654 ms |
306800 KB |
Output is correct |
12 |
Correct |
2159 ms |
470788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23936 KB |
Output is correct |
2 |
Correct |
12 ms |
24040 KB |
Output is correct |
3 |
Correct |
12 ms |
24192 KB |
Output is correct |
4 |
Correct |
12 ms |
24184 KB |
Output is correct |
5 |
Correct |
12 ms |
23932 KB |
Output is correct |
6 |
Correct |
12 ms |
24016 KB |
Output is correct |
7 |
Correct |
13 ms |
24192 KB |
Output is correct |
8 |
Correct |
12 ms |
24272 KB |
Output is correct |
9 |
Correct |
12 ms |
23988 KB |
Output is correct |
10 |
Correct |
13 ms |
24184 KB |
Output is correct |
11 |
Correct |
13 ms |
24140 KB |
Output is correct |
12 |
Correct |
14 ms |
24172 KB |
Output is correct |
13 |
Correct |
15 ms |
25284 KB |
Output is correct |
14 |
Correct |
17 ms |
26748 KB |
Output is correct |
15 |
Correct |
18 ms |
27116 KB |
Output is correct |
16 |
Correct |
21 ms |
29656 KB |
Output is correct |
17 |
Correct |
16 ms |
25352 KB |
Output is correct |
18 |
Correct |
21 ms |
26756 KB |
Output is correct |
19 |
Correct |
23 ms |
27068 KB |
Output is correct |
20 |
Correct |
20 ms |
27964 KB |
Output is correct |
21 |
Correct |
16 ms |
25280 KB |
Output is correct |
22 |
Correct |
17 ms |
26668 KB |
Output is correct |
23 |
Correct |
18 ms |
27068 KB |
Output is correct |
24 |
Correct |
20 ms |
27980 KB |
Output is correct |
25 |
Correct |
637 ms |
141180 KB |
Output is correct |
26 |
Correct |
1169 ms |
249992 KB |
Output is correct |
27 |
Correct |
1646 ms |
309412 KB |
Output is correct |
28 |
Correct |
2098 ms |
476720 KB |
Output is correct |
29 |
Correct |
698 ms |
139244 KB |
Output is correct |
30 |
Correct |
1247 ms |
246344 KB |
Output is correct |
31 |
Correct |
1722 ms |
304636 KB |
Output is correct |
32 |
Correct |
2296 ms |
469232 KB |
Output is correct |
33 |
Correct |
682 ms |
139700 KB |
Output is correct |
34 |
Correct |
1182 ms |
247180 KB |
Output is correct |
35 |
Correct |
1654 ms |
306800 KB |
Output is correct |
36 |
Correct |
2159 ms |
470788 KB |
Output is correct |
37 |
Correct |
1088 ms |
141668 KB |
Output is correct |
38 |
Correct |
1553 ms |
250584 KB |
Output is correct |
39 |
Correct |
1909 ms |
311992 KB |
Output is correct |
40 |
Correct |
2295 ms |
476808 KB |
Output is correct |
41 |
Correct |
1256 ms |
139780 KB |
Output is correct |
42 |
Correct |
1787 ms |
246636 KB |
Output is correct |
43 |
Correct |
2144 ms |
304940 KB |
Output is correct |
44 |
Correct |
2560 ms |
469420 KB |
Output is correct |
45 |
Correct |
1309 ms |
140124 KB |
Output is correct |
46 |
Correct |
1836 ms |
247532 KB |
Output is correct |
47 |
Correct |
2129 ms |
305788 KB |
Output is correct |
48 |
Correct |
2434 ms |
470928 KB |
Output is correct |