Submission #101968
Source Code Expand
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000];
int b[1 << 21][3];
int add(int x, int y, int z, int w)
{
if (z < 0) {
if (b[x][2] == -1) b[x][2] = w;
return 1;
} else {
if ((y >> z) & 1) {
b[x][0] = add(x * 2, y, z - 1, w);
} else {
b[x][1] = add(x * 2 + 1, y, z - 1, w);
}
return b[x][0] + b[x][1];
}
}
pair<int, pair<int, int> > get(int x, int y, int z)
{
if (z < 0) {
return make_pair(0, make_pair(min(b[x][2], b[y][2]), max(b[x][2], b[y][2])));
} else {
pair<int, pair<int, int> > ans = make_pair(-1, make_pair(1e9, 1e9)), p;
if ((b[x][0] == 0 || b[y][1] == 0) && (b[x][1] == 0 || b[y][0] == 0)) {
if (b[x][0] > 0 && b[y][0] > 0) {
p = get(x * 2, y * 2, z - 1);
if (p.first > ans.first || (p.first == ans.first && p.second.first < ans.second.first) || (p.first == ans.first && p.second.first == ans.second.first && p.second.second < ans.second.second)) ans = p;
}
if (b[x][1] > 0 && b[y][1] > 0) {
p = get(x * 2 + 1, y * 2 + 1, z - 1);
if (p.first > ans.first || (p.first == ans.first && p.second.first < ans.second.first) || (p.first == ans.first && p.second.first == ans.second.first && p.second.second < ans.second.second)) ans = p;
}
} else {
if (b[x][0] > 0 && b[y][1] > 0) {
p = get(x * 2, y * 2 + 1, z - 1);
if (p.first > ans.first || (p.first == ans.first && p.second.first < ans.second.first) || (p.first == ans.first && p.second.first == ans.second.first && p.second.second < ans.second.second)) ans = p;
}
if (b[x][1] > 0 && b[y][0] > 0) {
p = get(x * 2 + 1, y * 2, z - 1);
if (p.first > ans.first || (p.first == ans.first && p.second.first < ans.second.first) || (p.first == ans.first && p.second.first == ans.second.first && p.second.second < ans.second.second)) ans = p;
}
ans.first |= (1 << z);
}
return ans;
}
}
int main()
{
int n, x = 0, i;
pair<int, pair<int, int> > p;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < (1 << 21); i++) b[i][2] = -1;
add(1, 0, 19, 0);
for (i = 0; i < n; i++) {
x ^= a[i];
add(1, x, 19, i + 1);
}
if (b[1][0] + b[1][1] == 1) {
puts("0 1 1");
return 0;
}
p = get(1, 1, 19);
printf("%d %d %d\n", p.first, p.second.first + 1, p.second.second);
return 0;
}
Submission Info
Submission Time
2013-09-21 12:37:42+0900
Task
F - Maximum Segment XOR
User
not_shiokawa
Language
C++ (G++ 4.6.4)
Score
100
Code Size
2931 Byte
Status
AC
Exec Time
128 ms
Memory
25640 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:70:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:72:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
Judge Result
Set Name
All
Score / Max Score
100 / 100
Status
Set Name
Test Cases
All
1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 4, 5, 6, 7, 8, 9
Case Name
Status
Exec Time
Memory
1
AC
54 ms
25260 KB
10
AC
55 ms
25256 KB
11
AC
55 ms
25244 KB
12
AC
55 ms
25256 KB
13
AC
58 ms
25244 KB
14
AC
61 ms
25256 KB
15
AC
62 ms
25240 KB
16
AC
87 ms
25512 KB
17
AC
80 ms
25384 KB
18
AC
128 ms
25636 KB
19
AC
54 ms
25260 KB
2
AC
54 ms
25256 KB
20
AC
55 ms
25260 KB
21
AC
54 ms
25248 KB
22
AC
53 ms
25256 KB
23
AC
57 ms
25196 KB
24
AC
54 ms
25256 KB
25
AC
56 ms
25260 KB
26
AC
56 ms
25260 KB
27
AC
58 ms
25244 KB
28
AC
98 ms
25512 KB
29
AC
104 ms
25568 KB
3
AC
54 ms
25252 KB
30
AC
82 ms
25380 KB
31
AC
111 ms
25640 KB
4
AC
55 ms
25204 KB
5
AC
55 ms
25248 KB
6
AC
54 ms
25380 KB
7
AC
55 ms
25256 KB
8
AC
54 ms
25256 KB
9
AC
56 ms
25256 KB