1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
int ask(int l, int r) {
int op;
cout << "? " << l << ' ' << r << '\n';
cout.flush();
cin >> op;
return op;
}
void report(char sum) {
cout << "! " << sum << '\n';
cout.flush();
}
void solve() {
int n;
cin >> n;
vi a(n);
rep(i, 0, n - 1) {
cin >> a[i];
a[i]--;
}
vi cnt(n, -1);
rep(i, 0, n - 1) { cnt[a[i]] = i; }
int idx = -1;
rep(i, 0, n - 1) {
if (cnt[i] == -1) {
idx = i;
break;
}
}
if (idx != -1) {
int idx2 = -1;
rep(i, 0, n - 1) {
if (i == idx) continue;
idx2 = i;
break;
}
int op = ask(idx + 1, idx2 + 1);
if (op == 0)
report('A');
else
report('B');
return;
}
int op = ask(cnt[0] + 1, cnt[n - 1] + 1);
int op2 = ask(cnt[n - 1] + 1, cnt[0] + 1);
if (op + op2 > n)
report('B');
else
report('A');
return;
}
|