답안 #223660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223660 2020-04-15T23:56:46 Z dantoh000 Klasika (COCI20_klasika) C++14
110 / 110
3055 ms 474032 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
typedef pair<int,int> ii;
typedef pair<char,ii> Query;
vector<Query> queries;
vector<int> adjlist[N];
const int INF = 1000000000;
int num[N], l[N], r[N];
int ct = 1;

struct node{
    int s,e,m;
    set<int> v;
    node *l = NULL, *r = NULL;
    node (int _s, int _e): s(_s), e(_e){
        m = (s+e)/2;
    }
    void up(int x, int nv){
        //printf("update %d %d %d\n",s,e,x);
        v.insert(nv);
        if (s == e){
            return;
        }
        if (x <= m){
            if (l == NULL) l = new node(s,m);
            l->up(x,nv);
        }
        else{
            if (r == NULL) r = new node(m+1,e);
            r->up(x,nv);
        }
    }
    int query(int id, int x, int L, int R){
        //printf("segment tree: %d %d %d %d\n",s,e,id,x);
        if (s == e){
            return s^x;
        }
        if (x & (1<<id)){
            //printf("prefer left\n");
            if (l == NULL || l->v.lower_bound(L) == l->v.end() || *(l->v.lower_bound(L)) > R){
                //printf("right anyway\n");
                return r->query(id-1,x,L,R);
            }
            else return l->query(id-1,x,L,R);
        }
        else{
            //printf("prefer right\n");
            if (r == NULL || r->v.lower_bound(L) == r->v.end() || *(r->v.lower_bound(L)) > R) {
                //printf("left anyway\n");
                return l->query(id-1,x,L,R);
            }
            else return r->query(id-1,x,L,R);
        }
    }
}*root;
void dfs(int u, int p){
    l[u] = ct++;
    for (auto v : adjlist[u]){
        if (v == p) continue;
        dfs(v,u);
    }
    r[u] = ct++;
}
int main() {
	int q;
	cin >> q;
    root = new node(0,(int)((unsigned)(1<<31)-1));
	while (q--) {
        string Q;
        int a,b;
		cin >> Q >> a >> b;
		queries.push_back({Q[0],{a,b}});
		if (Q == "Add"){
            num[++ct] = num[a]^b;
            adjlist[a].push_back(ct);
		}
	}
	ct = 1;
	dfs(1,-1);
	root->up(0,l[1]);
	ct = 1;
	for (auto qu : queries){
        char Q = qu.first;
        int a = qu.second.first, b = qu.second.second;
        if (Q == 'A'){
            ct++;
            root->up(num[ct],l[ct]);
        }
        else{
            printf("%d\n",root->query(30,num[a],l[b],r[b]));
        }
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 8 ms 5504 KB Output is correct
4 Correct 8 ms 5632 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 8 ms 5376 KB Output is correct
7 Correct 7 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 8 ms 5504 KB Output is correct
4 Correct 8 ms 5632 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 8 ms 5376 KB Output is correct
7 Correct 7 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
13 Correct 12 ms 6656 KB Output is correct
14 Correct 14 ms 8064 KB Output is correct
15 Correct 16 ms 9472 KB Output is correct
16 Correct 18 ms 10752 KB Output is correct
17 Correct 13 ms 6528 KB Output is correct
18 Correct 15 ms 7936 KB Output is correct
19 Correct 17 ms 9344 KB Output is correct
20 Correct 19 ms 10624 KB Output is correct
21 Correct 13 ms 6528 KB Output is correct
22 Correct 15 ms 7936 KB Output is correct
23 Correct 18 ms 9344 KB Output is correct
24 Correct 18 ms 10624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1049 ms 134504 KB Output is correct
2 Correct 1397 ms 250880 KB Output is correct
3 Correct 1958 ms 360424 KB Output is correct
4 Correct 2447 ms 473548 KB Output is correct
5 Correct 1130 ms 132632 KB Output is correct
6 Correct 1552 ms 246484 KB Output is correct
7 Correct 2127 ms 355620 KB Output is correct
8 Correct 2840 ms 464372 KB Output is correct
9 Correct 1102 ms 132080 KB Output is correct
10 Correct 1494 ms 247316 KB Output is correct
11 Correct 2069 ms 358052 KB Output is correct
12 Correct 2538 ms 466596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5248 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 8 ms 5504 KB Output is correct
4 Correct 8 ms 5632 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 8 ms 5376 KB Output is correct
7 Correct 7 ms 5504 KB Output is correct
8 Correct 8 ms 5632 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 8 ms 5376 KB Output is correct
11 Correct 8 ms 5504 KB Output is correct
12 Correct 8 ms 5632 KB Output is correct
13 Correct 12 ms 6656 KB Output is correct
14 Correct 14 ms 8064 KB Output is correct
15 Correct 16 ms 9472 KB Output is correct
16 Correct 18 ms 10752 KB Output is correct
17 Correct 13 ms 6528 KB Output is correct
18 Correct 15 ms 7936 KB Output is correct
19 Correct 17 ms 9344 KB Output is correct
20 Correct 19 ms 10624 KB Output is correct
21 Correct 13 ms 6528 KB Output is correct
22 Correct 15 ms 7936 KB Output is correct
23 Correct 18 ms 9344 KB Output is correct
24 Correct 18 ms 10624 KB Output is correct
25 Correct 1049 ms 134504 KB Output is correct
26 Correct 1397 ms 250880 KB Output is correct
27 Correct 1958 ms 360424 KB Output is correct
28 Correct 2447 ms 473548 KB Output is correct
29 Correct 1130 ms 132632 KB Output is correct
30 Correct 1552 ms 246484 KB Output is correct
31 Correct 2127 ms 355620 KB Output is correct
32 Correct 2840 ms 464372 KB Output is correct
33 Correct 1102 ms 132080 KB Output is correct
34 Correct 1494 ms 247316 KB Output is correct
35 Correct 2069 ms 358052 KB Output is correct
36 Correct 2538 ms 466596 KB Output is correct
37 Correct 2088 ms 135856 KB Output is correct
38 Correct 2241 ms 250832 KB Output is correct
39 Correct 2534 ms 364980 KB Output is correct
40 Correct 2787 ms 474032 KB Output is correct
41 Correct 1725 ms 132972 KB Output is correct
42 Correct 2389 ms 246168 KB Output is correct
43 Correct 2978 ms 355652 KB Output is correct
44 Correct 3055 ms 463816 KB Output is correct
45 Correct 1798 ms 132612 KB Output is correct
46 Correct 2354 ms 247564 KB Output is correct
47 Correct 2635 ms 356772 KB Output is correct
48 Correct 2823 ms 466828 KB Output is correct