# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223403 | 2020-04-15T08:50:22 Z | dwsc | Klasika (COCI20_klasika) | C++14 | 3559 ms | 191136 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; vector<int> adj[200005]; int start[200005],fin[200005]; int num = 0; void dfs(int u,int pa){ start[u] = num; for (int i = 0; i < adj[u].size(); i++){ int v = adj[u][i]; if (v == pa) continue; dfs(v,u); } fin[u] = num++; } struct node { node *l, *r; set<int> st; int s, m, e; node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), l(NULL), r(NULL) { if (s != e) l = new node(s, m), r = new node(m+1, e); } void add(int x,int v){ // cout << "In" << s << " " << e << "\n"; // cout << "Adding" << x << " of weight " << v << "\n"; st.insert(v); if (s != e){ if (x <= m) l->add(x,v); else r->add(x,v); } } int query(int x,int y,int v){ if (s == x && e == y){ //cout <<"Calculating for"<< x << " " << y <<" " << v << "\nSet elements"; //for (auto it = st.begin(); it != st.end(); ++it) cout << *it << " "; //cout << "\n"; int lo = 0,hi = (1<<30)-1; for (int i = 29; i >= 0; i--){ //cout << i << "th bit " << lo << " " << hi << "\n"; if (v & (1<<i)){ // cout << "zero is better\n"; int mid = hi-(1<<i); auto it = st.lower_bound(lo); if (it ==st.end() || *it > mid) lo += (1<<i); else hi -= (1<<i); } else{ //cout << "one is better\n"; int mid = lo+(1<<i); auto it = st.lower_bound(mid); if (it == st.end() || *it > hi) hi -= (1<<i); else lo += (1<<i); } } //cout << lo << " " << hi << "done\n"; assert(lo == hi); return (lo^v); } if (y <= m) return l->query(x,y,v); if (x > m) return r->query(x,y,v); return max(l->query(x,m,v),r->query(m+1,y,v)); } }*root; int weight[200005]; int main(){ int q; cin >> q; int n = 1; ii que[q]; int type[q]; for (int i = 0; i < q; i++){ string t; cin >> t; if (t == "Add"){ int x,w; cin >> x >> w; x--; adj[x].push_back(n); weight[n] = weight[x]^w; que[i] = ii(n,weight[n]); type[i] = 0; n++; } else{ int a,b; cin >> a >> b; a--; b--; que[i] = ii(a,b); type[i] = 1; } } root = new node(0,n-1); dfs(0,-1); root->add(fin[0],0); for (int i = 0; i < q; i++){ if (type[i]){ int a = que[i].first,b = que[i].second; cout << root->query(start[b],fin[b],weight[a]) << "\n"; } else{ int x = que[i].first,w = que[i].second; root->add(fin[x],w); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 4992 KB | Output is correct |
6 | Correct | 8 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 4992 KB | Output is correct |
10 | Correct | 8 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 4992 KB | Output is correct |
6 | Correct | 8 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 4992 KB | Output is correct |
10 | Correct | 8 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
13 | Correct | 16 ms | 5376 KB | Output is correct |
14 | Correct | 17 ms | 5760 KB | Output is correct |
15 | Correct | 17 ms | 6016 KB | Output is correct |
16 | Correct | 19 ms | 6528 KB | Output is correct |
17 | Correct | 13 ms | 5376 KB | Output is correct |
18 | Correct | 13 ms | 5632 KB | Output is correct |
19 | Correct | 13 ms | 6016 KB | Output is correct |
20 | Correct | 14 ms | 6272 KB | Output is correct |
21 | Correct | 13 ms | 5376 KB | Output is correct |
22 | Correct | 14 ms | 5632 KB | Output is correct |
23 | Correct | 15 ms | 6016 KB | Output is correct |
24 | Correct | 17 ms | 6272 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 942 ms | 50912 KB | Output is correct |
2 | Correct | 1173 ms | 96220 KB | Output is correct |
3 | Correct | 1326 ms | 142104 KB | Output is correct |
4 | Correct | 1428 ms | 189944 KB | Output is correct |
5 | Correct | 1070 ms | 48504 KB | Output is correct |
6 | Correct | 1576 ms | 91768 KB | Output is correct |
7 | Correct | 2134 ms | 135160 KB | Output is correct |
8 | Correct | 2511 ms | 180344 KB | Output is correct |
9 | Correct | 936 ms | 48576 KB | Output is correct |
10 | Correct | 1201 ms | 92536 KB | Output is correct |
11 | Correct | 1438 ms | 136892 KB | Output is correct |
12 | Correct | 1689 ms | 182508 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 4992 KB | Output is correct |
6 | Correct | 8 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 4992 KB | Output is correct |
10 | Correct | 8 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
13 | Correct | 16 ms | 5376 KB | Output is correct |
14 | Correct | 17 ms | 5760 KB | Output is correct |
15 | Correct | 17 ms | 6016 KB | Output is correct |
16 | Correct | 19 ms | 6528 KB | Output is correct |
17 | Correct | 13 ms | 5376 KB | Output is correct |
18 | Correct | 13 ms | 5632 KB | Output is correct |
19 | Correct | 13 ms | 6016 KB | Output is correct |
20 | Correct | 14 ms | 6272 KB | Output is correct |
21 | Correct | 13 ms | 5376 KB | Output is correct |
22 | Correct | 14 ms | 5632 KB | Output is correct |
23 | Correct | 15 ms | 6016 KB | Output is correct |
24 | Correct | 17 ms | 6272 KB | Output is correct |
25 | Correct | 942 ms | 50912 KB | Output is correct |
26 | Correct | 1173 ms | 96220 KB | Output is correct |
27 | Correct | 1326 ms | 142104 KB | Output is correct |
28 | Correct | 1428 ms | 189944 KB | Output is correct |
29 | Correct | 1070 ms | 48504 KB | Output is correct |
30 | Correct | 1576 ms | 91768 KB | Output is correct |
31 | Correct | 2134 ms | 135160 KB | Output is correct |
32 | Correct | 2511 ms | 180344 KB | Output is correct |
33 | Correct | 936 ms | 48576 KB | Output is correct |
34 | Correct | 1201 ms | 92536 KB | Output is correct |
35 | Correct | 1438 ms | 136892 KB | Output is correct |
36 | Correct | 1689 ms | 182508 KB | Output is correct |
37 | Correct | 3420 ms | 50952 KB | Output is correct |
38 | Correct | 3559 ms | 96980 KB | Output is correct |
39 | Correct | 3177 ms | 144104 KB | Output is correct |
40 | Correct | 2575 ms | 191136 KB | Output is correct |
41 | Correct | 994 ms | 49400 KB | Output is correct |
42 | Correct | 1434 ms | 92152 KB | Output is correct |
43 | Correct | 1900 ms | 135672 KB | Output is correct |
44 | Correct | 2458 ms | 181080 KB | Output is correct |
45 | Correct | 1626 ms | 49412 KB | Output is correct |
46 | Correct | 1907 ms | 93136 KB | Output is correct |
47 | Correct | 1981 ms | 136952 KB | Output is correct |
48 | Correct | 1824 ms | 183288 KB | Output is correct |