답안 #1017339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017339 2024-07-09T07:28:04 Z vjudge1 Klasika (COCI20_klasika) C++17
66 / 110
362 ms 70752 KB
#include<bits/stdc++.h>

using namespace std;

struct node
{
  node * ch[2];
  node()
  {
    ch[0] = ch[1] = NULL;
  }
  
  void insert(int x, int b = 30)
  {
    if(b == -1) return;
    bool bit = (1 << b) & x;
    if(ch[bit] == NULL)
      ch[bit] = new node();
    ch[bit] -> insert(x, b - 1);
  }

  int query(int x, int b = 30)
  {
    if(b == -1) return 0;
    bool bit = (1 << b) & x;
    if(ch[!bit] != NULL)
      return (1 << b) + ch[!bit] -> query(x, b - 1);
    return ch[bit] -> query(x, b - 1);
  }
};
const int N = 2e5+5, M = 2000 + 10;
node *Tries[1];
int path[N], par[M];
vector<int> sub[M];

int main()
{
  int q;
  cin >> q;
  int cnt = 1;
  Tries[1] = new node();
  Tries[1] -> insert(path[1]);
  sub[1].push_back(1);
  for(int i = 0; i < q; i++)
    {
      string cmd;
      int a, b;
      cin >> cmd >> a >> b;
      if(cmd == "Query")
	{
	  if(q > 2000)
	    cout << Tries[b] -> query(path[a]) << endl;
	  else
	    {
	      int ans = 0;
	      for(int i : sub[b])
		ans = max(ans, path[i] ^ path[a]);
	      cout << ans << endl;
	    }
	}
      else
	{
	  cnt++;
	  path[cnt] = path[a] ^ b;
	  if(q > 2000)
	    Tries[1] -> insert(path[cnt]);
	  else
	    {
	      par[cnt] = a;
	      int cur = cnt;
	      while(cur > 0)
		{
		  sub[cur].push_back(cnt);
		  cur = par[cur];
		}
	    }
	}
    }
  
  return 0;
}

Compilation message

klasika.cpp: In function 'int main()':
klasika.cpp:41:10: warning: array subscript 1 is above array bounds of 'node* [1]' [-Warray-bounds]
   41 |   Tries[1] = new node();
      |   ~~~~~~~^
klasika.cpp:32:7: note: while referencing 'Tries'
   32 | node *Tries[1];
      |       ^~~~~
klasika.cpp:66:13: warning: array subscript 1 is above array bounds of 'node* [1]' [-Warray-bounds]
   66 |      Tries[1] -> insert(path[cnt]);
      |      ~~~~~~~^
klasika.cpp:32:7: note: while referencing 'Tries'
   32 | node *Tries[1];
      |       ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 8 ms 2456 KB Output is correct
15 Correct 8 ms 4856 KB Output is correct
16 Correct 14 ms 7772 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 2 ms 644 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 5 ms 656 KB Output is correct
23 Correct 5 ms 1324 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 324 ms 21976 KB Output is correct
2 Correct 322 ms 39056 KB Output is correct
3 Correct 362 ms 55012 KB Output is correct
4 Correct 261 ms 70648 KB Output is correct
5 Correct 348 ms 22056 KB Output is correct
6 Correct 315 ms 39248 KB Output is correct
7 Correct 301 ms 55188 KB Output is correct
8 Correct 279 ms 70752 KB Output is correct
9 Correct 326 ms 22024 KB Output is correct
10 Correct 323 ms 39252 KB Output is correct
11 Correct 275 ms 55380 KB Output is correct
12 Correct 254 ms 70740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 8 ms 2456 KB Output is correct
15 Correct 8 ms 4856 KB Output is correct
16 Correct 14 ms 7772 KB Output is correct
17 Correct 5 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 2 ms 644 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 5 ms 656 KB Output is correct
23 Correct 5 ms 1324 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 324 ms 21976 KB Output is correct
26 Correct 322 ms 39056 KB Output is correct
27 Correct 362 ms 55012 KB Output is correct
28 Correct 261 ms 70648 KB Output is correct
29 Correct 348 ms 22056 KB Output is correct
30 Correct 315 ms 39248 KB Output is correct
31 Correct 301 ms 55188 KB Output is correct
32 Correct 279 ms 70752 KB Output is correct
33 Correct 326 ms 22024 KB Output is correct
34 Correct 323 ms 39252 KB Output is correct
35 Correct 275 ms 55380 KB Output is correct
36 Correct 254 ms 70740 KB Output is correct
37 Runtime error 1 ms 600 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -