#include <bits/stdc++.h>
using namespace std;
#define MAX_N 250005
int tr[3][30*MAX_N] ,root ,nn ,k;
void add(int&p ,int a ,int i ,int b = 30){
if(p == 0){
p = ++nn;
tr[2][p] = i;
}
if(b == -1)
return;
add(tr[a>>b&1][p] ,a ,i ,b-1);
}
int ask(int&p ,int a ,int b = 30){
if(p == 0) return 1e9;
if(b == -1) return tr[2][p];
int ret = 1e9;
bool s = k>>b&1 ,t = a>>b&1;
if(s)
ret = min(ret ,ask(tr[!t][p] ,a ,b-1));
else
ret = min({ret ,tr[2][tr[!t][p]] ,ask(tr[t][p] ,a ,b-1)});
return ret;
}
int main()
{
int n ,xr = 0;
scanf("%d%d",&n,&k);
tr[2][0] = 1e9;
add(root ,0 ,0);
pair <int ,int> ans = {-1e9 ,-1e9};
for(int a ,i=1; i<=n; i++){
scanf("%d",&a) ,xr ^= a;
int b = ask(root ,xr);
ans = max(ans ,make_pair(i-b ,-b-1));
add(root ,xr ,i);
}
printf("%d %d\n",-ans.second,ans.first);
}
Compilation message
xor.cpp: In function 'int main()':
xor.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
xor.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
36 | scanf("%d",&a) ,xr ^= 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 |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
8 ms |
1004 KB |
Output is correct |
6 |
Correct |
10 ms |
1132 KB |
Output is correct |
7 |
Correct |
11 ms |
1132 KB |
Output is correct |
8 |
Correct |
11 ms |
1132 KB |
Output is correct |
9 |
Correct |
53 ms |
10988 KB |
Output is correct |
10 |
Correct |
52 ms |
11116 KB |
Output is correct |
11 |
Correct |
59 ms |
11136 KB |
Output is correct |
12 |
Correct |
52 ms |
11116 KB |
Output is correct |
13 |
Correct |
55 ms |
11116 KB |
Output is correct |
14 |
Correct |
53 ms |
11140 KB |
Output is correct |
15 |
Correct |
50 ms |
11116 KB |
Output is correct |
16 |
Correct |
54 ms |
11004 KB |
Output is correct |
17 |
Correct |
162 ms |
23276 KB |
Output is correct |
18 |
Correct |
159 ms |
23404 KB |
Output is correct |
19 |
Correct |
152 ms |
23404 KB |
Output is correct |
20 |
Correct |
155 ms |
23348 KB |
Output is correct |