답안 #223453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223453 2020-04-15T09:28:59 Z oolimry Klasika (COCI20_klasika) C++14
33 / 110
5000 ms 284136 KB
    #include <bits/stdc++.h>
     
    using namespace std;
     
    int n = 1;
    int cnt = 0;
    static vector<int> adj[200005];
    static int low[200005];
    static int high[200005];
    static int XOR[200005];
     
    void dfs(int u){
    	low[u] = cnt;
    	high[u] = cnt;
    	cnt++;
    	for(int v : adj[u]){
    		dfs(v);
    		high[u] = max(high[u], high[v]);
    	}
    }
     
    typedef pair<int,int> ii;
    vector<ii> queries;
     
    int N = 0;
    bitset<70000000> tree;
     
    struct seg{
    	vector<int> dis;
    	int offset;
     
    	void get(int l){
    		dis.push_back(l);
    	}
    	
    	void getReady(){
    		offset = N;
    		N += dis.size();
    		sort(dis.begin(),dis.end());
    	}
    	
    	void update(int i){
    		i = lower_bound(dis.begin(),dis.end(), i) - dis.begin() + offset;
    		for(i += N;i > 0;i >>= 1) tree[i] = 1;
    	}
    	
    	int query(int l, int r){
    		int res = 0;
    		l = lower_bound(dis.begin(),dis.end(), l) - dis.begin() + offset;
    		r = upper_bound(dis.begin(),dis.end(), r) - dis.begin() + offset;
    		for(l += N, r += N;l < r;l >>= 1, r >>= 1){
    			if(l&1) res |= tree[l++];
    			if(r&1) res |= tree[--r];
    		}
    		return res;
    	}
    };
     
    static unordered_map<int, seg> m[33];
     
     
     
    int main(){
    	//freopen("i.txt","r",stdin);
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	int Q; cin >> Q;
    	queries.push_back(ii(-1,0));
    	
    	while(Q--){
    		string s; int a, b; 
    		cin >> s >> a >> b;
    		if(s[0] == 'A' || s[0] == 'a'){
    			a--;
    			assert(a < n);
    			adj[a].push_back(n);
    			XOR[n] = XOR[a] ^ b;
    			queries.push_back(ii(-1,n));
    			n++;
    		}
    		else{
    			assert(a-1 < n);
    			assert(b-1 < n);
    			queries.push_back(ii(a-1,b-1));
    		}
    	}
    	
    	
    	dfs(0);
    	
    	for(ii q : queries){
    		//cout << q.first << " " << q.second << "\n";
    		
    		if(q.first == -1){
    			int pos = low[q.second];
    			int x = XOR[q.second];
    			
    			for(int b = 0;b <= 30;b++){
    				m[b][x].get(pos);
    				x ^= ((x & (1<<b)));
    			}
    			
    			continue;
    		}
    	}
    	
    	unordered_map<int,seg> k;
    	for(int b = 0;b <= 30;b++){
    		for(auto &x : m[b]){
    			(x.second).getReady();
    		}
    	}
    		
    	for(ii q : queries){
    		//cout << q.first << " " << q.second << "\n";
    		
    		if(q.first == -1){
    			int pos = low[q.second];
    			int x = XOR[q.second];
    			
    			for(int b = 0;b <= 30;b++){
    				m[b][x].update(pos);
    				x ^= ((x & (1<<b)));
    			}
    			
    			continue;
    		}
    		
    		int other = XOR[q.first];
    		int L = low[q.second], R = high[q.second];
    		int cur = 0;
    		for(int b = 30;b >= 0;b--){
    			if((other & (1<<b)) == 0) cur ^= (1 << b);
    			
    			if(m[b][cur].query(L,R) == 0) cur ^= (1 << b);
    		}
    		
    		cout << (cur ^ other) << "\n";
    		
    	}
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 9 ms 5376 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 9 ms 5376 KB Output is correct
7 Correct 8 ms 5376 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 9 ms 5376 KB Output is correct
11 Correct 9 ms 5504 KB Output is correct
12 Correct 9 ms 5504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 9 ms 5376 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 9 ms 5376 KB Output is correct
7 Correct 8 ms 5376 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 9 ms 5376 KB Output is correct
11 Correct 9 ms 5504 KB Output is correct
12 Correct 9 ms 5504 KB Output is correct
13 Correct 21 ms 6528 KB Output is correct
14 Correct 20 ms 7552 KB Output is correct
15 Correct 24 ms 8576 KB Output is correct
16 Correct 30 ms 9088 KB Output is correct
17 Correct 16 ms 6528 KB Output is correct
18 Correct 22 ms 7552 KB Output is correct
19 Correct 23 ms 8448 KB Output is correct
20 Correct 31 ms 9080 KB Output is correct
21 Correct 16 ms 6528 KB Output is correct
22 Correct 20 ms 7424 KB Output is correct
23 Correct 23 ms 8320 KB Output is correct
24 Correct 25 ms 8960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2751 ms 102564 KB Output is correct
2 Correct 3801 ms 170116 KB Output is correct
3 Correct 4722 ms 234212 KB Output is correct
4 Execution timed out 5081 ms 284136 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 9 ms 5376 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 9 ms 5376 KB Output is correct
7 Correct 8 ms 5376 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 9 ms 5376 KB Output is correct
11 Correct 9 ms 5504 KB Output is correct
12 Correct 9 ms 5504 KB Output is correct
13 Correct 21 ms 6528 KB Output is correct
14 Correct 20 ms 7552 KB Output is correct
15 Correct 24 ms 8576 KB Output is correct
16 Correct 30 ms 9088 KB Output is correct
17 Correct 16 ms 6528 KB Output is correct
18 Correct 22 ms 7552 KB Output is correct
19 Correct 23 ms 8448 KB Output is correct
20 Correct 31 ms 9080 KB Output is correct
21 Correct 16 ms 6528 KB Output is correct
22 Correct 20 ms 7424 KB Output is correct
23 Correct 23 ms 8320 KB Output is correct
24 Correct 25 ms 8960 KB Output is correct
25 Correct 2751 ms 102564 KB Output is correct
26 Correct 3801 ms 170116 KB Output is correct
27 Correct 4722 ms 234212 KB Output is correct
28 Execution timed out 5081 ms 284136 KB Time limit exceeded
29 Halted 0 ms 0 KB -