제출 #198918

#제출 시각아이디문제언어결과실행 시간메모리
198918dimash241Klasika (COCI20_klasika)C++17
33 / 110
1098 ms276848 KiB
#pragma GCC target("avx2") #pragma GCC optimize("O3") # include <x86intrin.h> # include <bits/stdc++.h> # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define _USE_MATH_DEFINES_ #define ll long long #define ld long double #define Accepted 0 #define pb push_back #define mp make_pair #define sz(x) (int)(x.size()) #define every(x) x.begin(),x.end() #define F first #define S second #define lb lower_bound #define ub upper_bound #define For(i,x,y) for (ll i = x; i <= y; i ++) #define FOr(i,x,y) for (ll i = x; i >= y; i --) #define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) // ROAD to... Red inline void Input_Output () { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); } const double eps = 0.000001; const ld pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const ll MOD = 1e18 + 9; const ll INF = 1e18 + 123; const int inf = 2e9 + 11; const int mxn = 6e6 + 9; const int N = 6e5 + 123; const int M = 22; const int K = 30; const int pri = 997; const int Magic = 2101; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int n = 1; int ans[N]; int pref[N]; int Query[N]; vector < pair < int, int > > g[N], qb[N]; int f[N]; struct trie { int to[2]; int mn; trie () { to[0] = to[1] = 0; mn = inf; } } t[mxn]; vector < int > sub[N]; int ptr; int p[N]; inline void upd (int rt, int val, int id) { int v = rt; //cout << "root: " << rt << '\n'; //cout << rt << ' ' << val << ' ' << id << '\n'; for (int i = K; i >= 0; i --) { int bit = ((val >> i) & 1); if (!t[v].to[bit]) t[v].to[bit] = ++ptr; t[v].mn = min(t[v].mn, id); // cout << v << ' ' << t[v].to[bit] << '\n'; v = t[v].to[bit]; } t[v].mn = min(t[v].mn, id); } inline int get (int rt, int val, int r) { int v = rt; int res = 0; for (int i = K; i >= 0; i --) { int bit = ((val >> i) & 1); bit ^= 1; //cout << bit << ' ' << //cout << t[v].to[bit] << ' ' << t[t[v].to[bit]].mn << '\n'; if (t[t[v].to[bit]].mn <= r) { res |= (1 << i); v = t[v].to[bit]; } else { bit ^= 1; v = t[v].to[bit]; } } //cout << res << ' ' << t[v].mn << '\n'; return res; } void dfs (int v, int pr = 0) { //cout << v << ' ' << f[v] << '\n'; p[v] = ++ptr; for (auto to : g[v]) { f[to.F] = (f[v] ^ to.S); dfs(to.F); } } void _merge (int v, int to) { if (sub[p[v]].size() < sub[p[to]].size()) { swap(p[v], p[to]); } for (auto x : sub[p[to]]) { sub[p[v]].pb(x); upd (p[v], f[x], x); } } void show (int rt) { int v = rt; cout << "sh: " << v << ' ' << t[v].mn << '\n'; if (t[v].to[0]) { show(t[v].to[0]); } if (t[v].to[1]) { show(t[v].to[1]); } } void go (int v, int pr = 0) { sub[p[v]].pb(v); //cout << "check: " << p[v] << ' ' << f[v] << ' ' << v << '\n'; upd (p[v], f[v], v); for (auto to : g[v]) { go(to.F); _merge(v, to.F); } //exit(0); for (auto x : qb[v]) { //cout << f[x.S] << ' ' << get(p[v], f[x.S], pref[x.F]) << '\n'; // cout << x.F << ":\n"; ans[x.F] = get(p[v], f[x.S], pref[x.F]); } } int main () { SpeedForce; int m; cin >> m; for (int i = 1; i <= m; i ++) { string type; cin >> type; if (type == "Add") { int x, y; cin >> x >> y; g[x].pb(mp(++n, y)); } else { int a, b; cin >> a >> b; qb[b].pb(mp(i, a)); Query[i] = 1; } pref[i] = n; } dfs(1); go(1); for (int i = 1; i <= m; i++) if (Query[i]) cout << ans[i] << '\n'; return Accepted; } // B...a
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...