# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087007 |
2024-09-12T03:29:15 Z |
vjudge1 |
Klasika (COCI20_klasika) |
C++14 |
|
416 ms |
524288 KB |
#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.reserve(1000);
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) {
if (!m) {
return 0;
}
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 << 2 | 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) >> 1;
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;
seg.update(in[1], 0);
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
klasika.cpp: In function 'int main()':
klasika.cpp:141:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
141 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:142:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
142 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5464 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6744 KB |
Output is correct |
5 |
Correct |
3 ms |
5464 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
5424 KB |
Output is correct |
10 |
Correct |
2 ms |
6244 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
12 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5464 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6744 KB |
Output is correct |
5 |
Correct |
3 ms |
5464 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
5424 KB |
Output is correct |
10 |
Correct |
2 ms |
6244 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
12 |
Correct |
4 ms |
6748 KB |
Output is correct |
13 |
Correct |
10 ms |
9560 KB |
Output is correct |
14 |
Correct |
9 ms |
14168 KB |
Output is correct |
15 |
Correct |
11 ms |
18524 KB |
Output is correct |
16 |
Correct |
12 ms |
23104 KB |
Output is correct |
17 |
Correct |
7 ms |
9308 KB |
Output is correct |
18 |
Correct |
12 ms |
14132 KB |
Output is correct |
19 |
Correct |
11 ms |
18268 KB |
Output is correct |
20 |
Correct |
14 ms |
23220 KB |
Output is correct |
21 |
Correct |
6 ms |
9564 KB |
Output is correct |
22 |
Correct |
12 ms |
13940 KB |
Output is correct |
23 |
Correct |
11 ms |
18264 KB |
Output is correct |
24 |
Correct |
19 ms |
22960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
480612 KB |
Output is correct |
2 |
Runtime error |
416 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5464 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6744 KB |
Output is correct |
5 |
Correct |
3 ms |
5464 KB |
Output is correct |
6 |
Correct |
3 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
5424 KB |
Output is correct |
10 |
Correct |
2 ms |
6244 KB |
Output is correct |
11 |
Correct |
3 ms |
6232 KB |
Output is correct |
12 |
Correct |
4 ms |
6748 KB |
Output is correct |
13 |
Correct |
10 ms |
9560 KB |
Output is correct |
14 |
Correct |
9 ms |
14168 KB |
Output is correct |
15 |
Correct |
11 ms |
18524 KB |
Output is correct |
16 |
Correct |
12 ms |
23104 KB |
Output is correct |
17 |
Correct |
7 ms |
9308 KB |
Output is correct |
18 |
Correct |
12 ms |
14132 KB |
Output is correct |
19 |
Correct |
11 ms |
18268 KB |
Output is correct |
20 |
Correct |
14 ms |
23220 KB |
Output is correct |
21 |
Correct |
6 ms |
9564 KB |
Output is correct |
22 |
Correct |
12 ms |
13940 KB |
Output is correct |
23 |
Correct |
11 ms |
18264 KB |
Output is correct |
24 |
Correct |
19 ms |
22960 KB |
Output is correct |
25 |
Correct |
401 ms |
480612 KB |
Output is correct |
26 |
Runtime error |
416 ms |
524288 KB |
Execution killed with signal 9 |
27 |
Halted |
0 ms |
0 KB |
- |