Submission #1086992

#TimeUsernameProblemLanguageResultExecution timeMemory
1086992vjudge1Klasika (COCI20_klasika)C++14
0 / 110
256 ms167548 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "" #define ll long long #define pii pair < int , int > #define fi first #define se second #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++) #define bit(x, i) (((x) >> (i)) & 1ll) #define mask(x) (1ll << (x)) #define mem(f, x) memset(f, x, sizeof(f)) #define sz(x) (int32_t) (x.size()) const int nmax = 2e5; int in[nmax + 5], out[nmax + 5], timer = 0, a[nmax + 5]; bool type[nmax + 5]; pii query[nmax + 5]; vector < int > adj[nmax + 5]; void dfs(int i) { in[i] = ++ timer; for (auto x: adj[i]) { dfs(x); } out[i] = timer; } struct SegTree { struct Trie { struct Node{ int child[2]; Node() { child[0] = child[1] = -1; } }; int m = -1; vector < Node > a; void create() { ++ m; a.push_back(Node()); } Trie() { create(); } void add(int x) { int pos = 0; FORD(i, 30, 0) { int c = bit(x, i); if (a[pos].child[c] == -1) { create(); a[pos].child[c] = m; } pos = a[pos].child[c]; } } int query(int x) { int res = 0, pos = 0; FORD(i, 30, 0) { int c = bit(x, i); if (a[pos].child[1 - c] != -1) { res ^= mask(i); pos = a[pos].child[1 - c]; } else { pos = a[pos].child[c]; } } return res; } }; int n; vector < Trie > b; void init(int _n) { n = _n; b.assign(n * 4 + 1, Trie()); } void update(int id, int l, int r, int i, int val) { b[id].add(val); if (l == r) { return; } int mid = (l + r) >> 1; if (mid >= i) { update(id << 1, l, mid, i, val); } else { update(id << 1 | 1, mid + 1, r, i, val); } } int get(int id, int l, int r, int u, int v, int val) { if (l > v || u > r) { return 0; } if (u <= l && r <= v) { return b[id].query(val); } int mid = (l + r) / 2; return max(get(id << 1, l, mid, u, v, val), get(id << 1 | 1, mid + 1, r, u, v, val)); } void update(int i, int val) { update(1, 1, n, i, val); } int get(int l, int r, int val) { return get(1, 1, n, l, r, val); } }seg; signed main() { if (fopen(NAME".inp", "r")) { freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int nq, n = 1; cin >> nq; FOR(i, 1, nq) { string s; cin >> s >> query[i].fi >> query[i].se; if (s == "Add") { type[i] = 1; adj[query[i].fi].push_back(++ n); } } dfs(1); seg.init(n); n = 1; FOR(i, 1, nq) { if (type[i]) { n ++; a[n] = a[query[i].fi] ^ query[i].se; seg.update(in[n], a[n]); } else { cout << seg.get(in[query[i].se], out[query[i].se], a[query[i].fi]) << "\n"; } } return 0; }

Compilation message (stderr)

klasika.cpp: In function 'int main()':
klasika.cpp:136:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |     freopen(NAME".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:137:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |     freopen(NAME".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...