이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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];
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |