답안 #223329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223329 2020-04-15T07:19:50 Z dantoh000 Klasika (COCI20_klasika) C++14
33 / 110
5000 ms 2540 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10, LOG_A = 31;
const int LOGN = 20;
int k;
int basis[LOG_A];
int num[N], d[N];
int p[N][LOGN];
int sz;
int ct = 1;
void insertVector(int mask) {
	for (int i = 0; i < LOG_A; i++) {
		if ((mask & 1 << i) == 0) continue;
		if (!basis[i]) {
			basis[i] = mask;
			++sz;
			return;
		}
		mask ^= basis[i];
	}
}
int maxxor(int cur){
    for (int i = LOG_A; i >= 0; i--){
        if ((cur & 1<<i) == 0){
            if (basis[i]){
                cur ^= basis[i];
            }
        }
    }
    return cur;
}
int is_parent(int u, int v){
    int dif = d[u] - d[v];
    if (dif < 0) return 0;
    while (dif){
        int lsb = 31-__builtin_clz(dif);
        u = p[u][lsb];
        dif -= (1<<lsb);
    }
    return (u==v);
}
int main() {
	int q;
	cin >> q;
	while (q--) {
        string Q;
        int a,b;
		cin >> Q >> a >> b;
		if (Q == "Add"){
            num[++ct] = num[a]^b;
            p[ct][0] = a;
            d[ct] = d[a]+1;
            for (int k = 1; k < LOGN; k++){
                if (p[ct][k-1] == -1) break;
                p[ct][k] = p[p[ct][k-1]][k-1];
            }
            insertVector(num[ct]);
		}
        else if (Q == "Query"){
            if (b == 1 && false) printf("%d\n",maxxor(num[a]));
            else{
                int ans = 0;
                for (int i = 1; i <= ct; i++){
                    if (is_parent(i,b)){
                        ans = max(ans,num[i]^num[a]);
                    }
                }
                printf("%d\n",ans);
            }
        }
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 13 ms 512 KB Output is correct
15 Correct 14 ms 512 KB Output is correct
16 Correct 11 ms 512 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 11 ms 512 KB Output is correct
20 Correct 11 ms 512 KB Output is correct
21 Correct 13 ms 384 KB Output is correct
22 Correct 14 ms 512 KB Output is correct
23 Correct 13 ms 512 KB Output is correct
24 Correct 11 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5069 ms 2540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 13 ms 512 KB Output is correct
15 Correct 14 ms 512 KB Output is correct
16 Correct 11 ms 512 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 11 ms 512 KB Output is correct
20 Correct 11 ms 512 KB Output is correct
21 Correct 13 ms 384 KB Output is correct
22 Correct 14 ms 512 KB Output is correct
23 Correct 13 ms 512 KB Output is correct
24 Correct 11 ms 512 KB Output is correct
25 Execution timed out 5069 ms 2540 KB Time limit exceeded
26 Halted 0 ms 0 KB -