Submission #481411

#TimeUsernameProblemLanguageResultExecution timeMemory
481411rainboyKlasika (COCI20_klasika)C11
66 / 110
5051 ms29144 KiB
#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 (stderr)

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--;
      |    ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...