QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370779#6394. Turn on the Lightricofx#WA 0ms3692kbC++17848b2024-03-29 16:33:012024-03-29 16:33:02

Judging History

你现在查看的是最新测评结果

  • [2024-03-29 16:33:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2024-03-29 16:33:01]
  • 提交

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