답안 #481411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481411 2021-10-20T17:39:33 Z rainboy Klasika (COCI20_klasika) C
66 / 110
5000 ms 29144 KB
#include <stdio.h>
#include <stdlib.h>

#define N	200001
#define L	30
#define N_	(1 + N * L)

int max(int a, int b) { return a > b ? a : b; }

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o == 0 || o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], (o == 0 ? 2 : o * 2) * sizeof *ej[i]);
	ej[i][o] = j;
}

int aa[N];

int dfs(int i, int a) {
	int x = aa[i] ^ a, o;

	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		x = max(x, dfs(j, a));
	}
	return x;
}

int tt[N_][2], _ = 2;

void update(int a) {
	int l, t;

	for (l = L - 1, t = 1; l >= 0; l--) {
		int c = a >> l & 1;

		if (!tt[t][c])
			tt[t][c] = _++;
		t = tt[t][c];
	}
}

int query(int a) {
	int l, t, x;

	x = 0;
	for (l = L - 1, t = 1; l >= 0; l--) {
		int c = (a >> l & 1) ^ 1;

		if (tt[t][c])
			x |= 1 << l;
		else
			c ^= 1;
		t = tt[t][c];
	}
	return x;
}

int main() {
	int n, q;

	scanf("%d", &q);
	n = 1;
	update(aa[0]);
	while (q--) {
		static char s[8];
		int i, j;

		scanf("%s%d", s, &i), i--;
		if (s[0] == 'A') {
			j = n++;
			scanf("%d", &aa[j]), aa[j] ^= aa[i];
			append(i, j);
			update(aa[j]);
		} else {
			scanf("%d", &j), j--;
			printf("%d\n", j == 0 ? query(aa[i]) : dfs(j, aa[i]));
		}
	}
	return 0;
}

Compilation message

klasika.c: In function 'append':
klasika.c:15:33: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |  if (o == 0 || o >= 2 && (o & o - 1) == 0)
      |                               ~~^~~
klasika.c:15:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   15 |  if (o == 0 || o >= 2 && (o & o - 1) == 0)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
klasika.c: In function 'main':
klasika.c:66:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
klasika.c:73:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   scanf("%s%d", s, &i), i--;
      |   ^~~~~~~~~~~~~~~~~~~~
klasika.c:76:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |    scanf("%d", &aa[j]), aa[j] ^= aa[i];
      |    ^~~~~~~~~~~~~~~~~~~
klasika.c:80:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |    scanf("%d", &j), j--;
      |    ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 2 ms 448 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10292 KB Output is correct
2 Correct 123 ms 17700 KB Output is correct
3 Correct 124 ms 23484 KB Output is correct
4 Correct 133 ms 29144 KB Output is correct
5 Correct 120 ms 11036 KB Output is correct
6 Correct 126 ms 16580 KB Output is correct
7 Correct 143 ms 21688 KB Output is correct
8 Correct 136 ms 26712 KB Output is correct
9 Correct 110 ms 11204 KB Output is correct
10 Correct 122 ms 16964 KB Output is correct
11 Correct 134 ms 22264 KB Output is correct
12 Correct 128 ms 27500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 588 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 2 ms 448 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 109 ms 10292 KB Output is correct
26 Correct 123 ms 17700 KB Output is correct
27 Correct 124 ms 23484 KB Output is correct
28 Correct 133 ms 29144 KB Output is correct
29 Correct 120 ms 11036 KB Output is correct
30 Correct 126 ms 16580 KB Output is correct
31 Correct 143 ms 21688 KB Output is correct
32 Correct 136 ms 26712 KB Output is correct
33 Correct 110 ms 11204 KB Output is correct
34 Correct 122 ms 16964 KB Output is correct
35 Correct 134 ms 22264 KB Output is correct
36 Correct 128 ms 27500 KB Output is correct
37 Execution timed out 5051 ms 8700 KB Time limit exceeded
38 Halted 0 ms 0 KB -