# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874571 |
2023-11-17T10:25:17 Z |
sleepntsheep |
XOR (IZhO12_xor) |
C++17 |
|
2000 ms |
856 KB |
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define N 250000
#define M 7000000
int n, x, z, a[N+1], zz;
int A[M], C[M][2], alloc = 1;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
void insert(int v, int x, int j, int i)
{
int b = (x >> j) & 1;
A[v] = max(A[v], i);
if (j)
{
if (!C[v][b]) C[v][b] = ++alloc;
insert(C[v][b], x, j-1, i);
A[v] = max(A[v], max(A[C[v][0]], A[C[v][1]]));
}
}
int query(int v, int x, int y, int j)
{
if (y <= 0) return A[v];
int b = (x >> j) & 1, z = -1;
if (j)
{
if (C[v][b^1] && A[C[v][b^1]] > z) z = max(z, query(C[v][b^1], x, y - (1 << j), j-1));
if (C[v][b] && A[C[v][b]] > z) z = max(z, query(C[v][b], x, y, j-1));
}
return z;
}
int main(void)
{
scanf("%d%d", &n, &x);
for (int i = 1; i <= n; ++i) scanf("%d", a+i), a[i] ^= a[i-1], insert(1, a[i], 31, i);
for (int b, i = 0; i < n; ++i) if ((b = query(1, a[i], x, 31) - i) > z)
z = b, zz = i + 1;
printf("%d %d", zz, z);
return 0;
}
Compilation message
xor.cpp: In function 'int main()':
xor.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~
xor.cpp:43:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | for (int i = 1; i <= n; ++i) scanf("%d", a+i), a[i] ^= a[i-1], insert(1, a[i], 31, i);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
348 KB |
Output is correct |
4 |
Correct |
80 ms |
504 KB |
Output is correct |
5 |
Execution timed out |
2007 ms |
856 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |