QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370779 | #6394. Turn on the Light | ricofx# | WA | 0ms | 3692kb | C++17 | 848b | 2024-03-29 16:33:01 | 2024-03-29 16:33:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int n, tr[N];
void add(int x) {
for (; x <= n; x += x & -x) tr[x] += 1;
}
int qry(int x) {
int res = 0;
for (; x; x -= x & -x) res += tr[x];
return res;
}
int qry(int l, int r) {
if (l > r) return 0;
return qry(r) - qry(l - 1);
}
int query(int x) {
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
int main() {
cin >> n;
int l = 1, r = n, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
int res = query(mid);
int left = qry(1, l - 1), right = qry(r + 1, n);
add(mid);
if (abs(left + 1 - right) == res) l = mid + 1;
else if (abs(left - right - 1) == res) r = mid - 1;
else return cout << "! " << mid << endl, 0;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
10 1 2 3 4
output:
? 5 ? 8 ? 9 ? 10
result:
wrong answer format Unexpected end of file - token expected