#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
using ll = long long;
using namespace std;
const int M = 8000000;
int n, q, a, b, cnt, to[M][2], mn[M];
pair<int, int> res;
void add(int pos, int x) {
int v = 0;
for (int i = 30; 0 <= i; --i) {
int b = (x >> i & 1);
if (!to[v][b]) to[v][b] = ++cnt, mn[cnt] = 1 << 30;
v = to[v][b];
mn[v] = min(mn[v], pos);
}
}
int query(int x) {
int v = 0, res = 1 << 30;
for (int i = 30; 0 <= i; --i) {
int b = (x >> i & 1);
if (q >> i & 1)
v = to[v][!b];
else {
res = min(res, mn[to[v][!b]]);
v = to[v][b];
}
if (!v) return res;
}
res = min(res, mn[v]);
return res;
}
int main() {
//~ memset(mn, 0x3f, sizeof mn);
mn[0] = 1 << 30;
scanf("%d%d", &n, &q);
add(0, 0);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
b ^= a;
int l = query(b);
res = max(res, {i - l, -l});
add(i, b);
}
printf("%d %d\n", -res.second + 1, res.first);
return 0;
}
Compilation message
xor.cpp: In function 'int main()':
xor.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
xor.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
7 ms |
1004 KB |
Output is correct |
6 |
Correct |
9 ms |
1132 KB |
Output is correct |
7 |
Correct |
9 ms |
1132 KB |
Output is correct |
8 |
Correct |
13 ms |
1132 KB |
Output is correct |
9 |
Correct |
50 ms |
10988 KB |
Output is correct |
10 |
Correct |
50 ms |
11116 KB |
Output is correct |
11 |
Correct |
49 ms |
11116 KB |
Output is correct |
12 |
Correct |
51 ms |
11116 KB |
Output is correct |
13 |
Correct |
52 ms |
11116 KB |
Output is correct |
14 |
Correct |
52 ms |
11244 KB |
Output is correct |
15 |
Correct |
52 ms |
11116 KB |
Output is correct |
16 |
Correct |
50 ms |
11116 KB |
Output is correct |
17 |
Correct |
161 ms |
23276 KB |
Output is correct |
18 |
Correct |
151 ms |
23512 KB |
Output is correct |
19 |
Correct |
146 ms |
23408 KB |
Output is correct |
20 |
Correct |
167 ms |
23532 KB |
Output is correct |