QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613687#8939. PermutationnekoyellowWA 6ms3656kbC++201005b2024-10-05 14:28:412024-10-05 14:28:48

Judging History

This is the latest submission verdict.

  • [2024-10-05 14:28:48]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 3656kb
  • [2024-10-05 14:28:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int query(int l, int r) {
    cout << "? " << l << ' ' << r << endl;
    int res;
    cin >> res;
    return res;
}

void solve(int i) {
    int n;
    cin >> n;
    int l = 1, r = n;
    int k = query(1, n);
    while (r-l > 1) {
        if (k < (l+r)/2) {
            int m = l + (r-l)*31/50;
            if (k == query(l, m)) r = m;
            else {
                l = m+1;
                if (l != r) k = query(l, r);
            }
        } else {
            int m = r - (r-l)*31/50;
            if (k == query(m, r)) l = m;
            else {
                r = m-1;
                if (l != r) k = query(l, r);
            }
        }
    }
    if (l == r) {
        cout << "! " << l << endl;
    } else {
        cout << "! " << (l == k ? r : l) << endl;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) solve(i);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

input:

3
5
3
3
3
6
6
3
1
4
3
3

output:

? 1 5
? 3 5
? 3 4
! 4
? 1 6
? 3 6
? 1 2
! 2
? 1 4
? 3 4
! 4

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 3652kb

input:

10000
10
2
2
2
3
1

output:

? 1 10
? 1 6
? 1 4
? 3 4
? 1 2
! 2

result:

wrong answer Wrong prediction (test case 1)