# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
197997 |
2020-01-24T12:58:17 Z |
ami |
Klasika (COCI20_klasika) |
C++17 |
|
1332 ms |
281708 KB |
#include <bits/stdc++.h>
#define sz(c) int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;
struct node {
int next[2];
node() {
next[0]=next[1]=-1;
}
};
const int bitlen=30;
struct trie {
vector<node> t;
trie():t(1) {}
void new_node(int v,int bit) {
t[v].next[bit]=sz(t);
t.emplace_back();
}
void add(int x) {
int v=0;
per(i,0,bitlen+1) {
int bit=x>>i&1;
if (t[v].next[bit]==-1) new_node(v,bit);
v=t[v].next[bit];
}
}
int getmax(int x) const {
int v=0,res=0;
per(i,0,bitlen+1) {
int bit=x>>i&1;
if (t[v].next[!bit]!=-1) {
res^=1<<i;
bit=!bit;
}
if (t[v].next[bit]==-1) return 0;
v=t[v].next[bit];
}
return res;
}
};
struct segtree {
using Item = trie;
using Change = int;
using Result = int;
int n;
vector<Item> tr;
vector<bool> used;
explicit segtree(int sz):n(sz),tr(2*n),used(2*n) {}
static void modify(Item &it, const Change &x) {
it.add(x);
}
static void check(Result &res, const Item &it, int x) {
res=max(res,it.getmax(x));
}
void mark_used(int l, int r) {
l+=n, r+=n;
while (l<=r) {
if (l%2==1) used[l]=true;
if (r%2==0) used[r]=true;
l=(l+1)/2;
r=(r-1)/2;
}
}
void add(int i, const Change &x) {
for (i+=n; i>0; i/=2) if (used[i]) modify(tr[i],x);
}
Result query(int l, int r, int x) const {
Result res{};
l+=n, r+=n;
while (l<=r) {
if (l%2==1) check(res,tr[l],x);
if (r%2==0) check(res,tr[r],x);
l=(l+1)/2;
r=(r-1)/2;
}
return res;
}
Item& operator[](int i) {
return tr[i+n];
}
};
vector<vector<int>> adj(1);
vector<int> xum(1);
vector<pair<int,int>> tio(1);
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout<<fixed<<setprecision(10);
int Q;
cin>>Q;
vector<tuple<string,int,int>> qs;
rep(i,0,Q) {
string s;
int a,b;
cin>>s>>a>>b;
if (s=="Add") {
a--;
int v=sz(adj);
adj[a].emplace_back(v);
adj.emplace_back();
tio.emplace_back();
xum.emplace_back(xum[a]^b);
a=v;
} else {
a--, b--;
}
qs.emplace_back(s,a,b);
}
int time=0;
function<void(int)> dfs=[&](int v) {
tio[v].first=time++;
fore(adj[v],u) dfs(u);
tio[v].second=time-1;
};
dfs(0);
segtree st(sz(xum));
fore(qs,&q) {
string s;
int a,b;
tie(s,a,b)=q;
if (s=="Query") st.mark_used(tio[b].first,tio[b].second);
}
st.add(0,xum[0]);
fore(qs,&q) {
string s;
int a,b;
tie(s,a,b)=q;
if (s=="Add") {
st.add(tio[a].first,xum[a]);
} else {
cout<<st.query(tio[b].first,tio[b].second,xum[a])<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
1016 KB |
Output is correct |
14 |
Correct |
7 ms |
1532 KB |
Output is correct |
15 |
Correct |
9 ms |
1972 KB |
Output is correct |
16 |
Correct |
8 ms |
2292 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
6 ms |
1400 KB |
Output is correct |
19 |
Correct |
6 ms |
1656 KB |
Output is correct |
20 |
Correct |
7 ms |
1784 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
6 ms |
1504 KB |
Output is correct |
23 |
Correct |
7 ms |
1784 KB |
Output is correct |
24 |
Correct |
7 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
533 ms |
27572 KB |
Output is correct |
2 |
Correct |
512 ms |
44268 KB |
Output is correct |
3 |
Correct |
479 ms |
59692 KB |
Output is correct |
4 |
Correct |
358 ms |
72244 KB |
Output is correct |
5 |
Correct |
877 ms |
28320 KB |
Output is correct |
6 |
Correct |
851 ms |
47896 KB |
Output is correct |
7 |
Correct |
500 ms |
56784 KB |
Output is correct |
8 |
Correct |
676 ms |
73260 KB |
Output is correct |
9 |
Correct |
885 ms |
28968 KB |
Output is correct |
10 |
Correct |
830 ms |
47160 KB |
Output is correct |
11 |
Correct |
702 ms |
55224 KB |
Output is correct |
12 |
Correct |
471 ms |
73724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
1016 KB |
Output is correct |
14 |
Correct |
7 ms |
1532 KB |
Output is correct |
15 |
Correct |
9 ms |
1972 KB |
Output is correct |
16 |
Correct |
8 ms |
2292 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
6 ms |
1400 KB |
Output is correct |
19 |
Correct |
6 ms |
1656 KB |
Output is correct |
20 |
Correct |
7 ms |
1784 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
6 ms |
1504 KB |
Output is correct |
23 |
Correct |
7 ms |
1784 KB |
Output is correct |
24 |
Correct |
7 ms |
2040 KB |
Output is correct |
25 |
Correct |
533 ms |
27572 KB |
Output is correct |
26 |
Correct |
512 ms |
44268 KB |
Output is correct |
27 |
Correct |
479 ms |
59692 KB |
Output is correct |
28 |
Correct |
358 ms |
72244 KB |
Output is correct |
29 |
Correct |
877 ms |
28320 KB |
Output is correct |
30 |
Correct |
851 ms |
47896 KB |
Output is correct |
31 |
Correct |
500 ms |
56784 KB |
Output is correct |
32 |
Correct |
676 ms |
73260 KB |
Output is correct |
33 |
Correct |
885 ms |
28968 KB |
Output is correct |
34 |
Correct |
830 ms |
47160 KB |
Output is correct |
35 |
Correct |
702 ms |
55224 KB |
Output is correct |
36 |
Correct |
471 ms |
73724 KB |
Output is correct |
37 |
Correct |
1192 ms |
84292 KB |
Output is correct |
38 |
Correct |
1266 ms |
158528 KB |
Output is correct |
39 |
Correct |
1332 ms |
229812 KB |
Output is correct |
40 |
Correct |
1133 ms |
281708 KB |
Output is correct |
41 |
Correct |
618 ms |
79976 KB |
Output is correct |
42 |
Correct |
908 ms |
150180 KB |
Output is correct |
43 |
Correct |
1165 ms |
207988 KB |
Output is correct |
44 |
Correct |
1201 ms |
232716 KB |
Output is correct |
45 |
Correct |
741 ms |
82664 KB |
Output is correct |
46 |
Correct |
910 ms |
157432 KB |
Output is correct |
47 |
Correct |
1008 ms |
218912 KB |
Output is correct |
48 |
Correct |
967 ms |
260548 KB |
Output is correct |