QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613280#8939. PermutationnekoyellowWA 84ms3640kbC++231.3kb2024-10-05 13:51:372024-10-05 13:51:40

Judging History

This is the latest submission verdict.

  • [2024-10-05 13:51:40]
  • Judged
  • Verdict: WA
  • Time: 84ms
  • Memory: 3640kb
  • [2024-10-05 13:51:37]
  • 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 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 + max((r-l)/3*2, 1);
            if (k <= m) {
                int nk = query(l, m);
                if (k == nk) r = m;
                else {
                    l = m+1;
                    if (l != r) k = query(l, r);
                }
            } else {
                l += max((r-l)/3, 1);
                k = query(l, r);
            }
        } else {
            int m = r - max((r-l)/3*2, 1);
            if (k >= m) {
                int nk = query(m, r);
                if (k == nk) l = m;
                else {
                    r = m-1;
                    if (l != r) k = query(l, r);
                }
            } else {
                r -= max((r-l)/3, 1);
                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 (; t; t--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 84ms
memory: 3580kb

input:

10000
10
2
2
2
3
5
10
10
10
10
8
7
10
5
5
5
4
8
10
4
4
4
4
5
10
10
6
3
2
10
3
3
3
5
2
10
1
5
9
10
10
1
1
3
6
10
2
4
9
9
10
3
3
3
3
3
10
4
7
8
9
10
8
7
1
2
10
4
1
9
9
10
7
7
8
4
10
5
5
7
10
10
8
8
8
8
9
10
2
2
1
7
10
6
6
4
10
10
1
1
3
6
10
7
9
1
2
10
7
4
1
2
10
3
4
10
10
10
4
4
4
4
4
10
8
7
2
3
10
8
...

output:

? 1 10
? 1 7
? 1 5
? 1 3
? 4 5
! 4
? 1 10
? 4 10
? 6 10
? 8 10
? 6 7
! 6
? 1 10
? 4 10
? 4 8
? 4 6
? 7 8
! 7
? 1 10
? 1 7
? 3 7
? 3 5
? 4 5
! 3
? 1 10
? 4 10
? 1 3
? 2 3
! 1
? 1 10
? 1 7
? 1 5
? 3 5
? 1 2
! 1
? 1 10
? 1 7
? 8 10
? 9 10
! 8
? 1 10
? 1 7
? 1 5
? 6 7
! 7
? 1 10
? 1 7
? 8 10
? 9 10
! 10...

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

10000
3
1
2
11
5
5
5
5
5
2
2
19
3
3
4
13
12
7
5
5
7
4
3
3
3
19
6
6
6
7
1
1
2
2
2
15
11
11
15
8
8
8
14
1
1
1
3
5
16
4
4
4
4
5
7
3
3
2
19
13
17
5
6
2
2
2
2
4
1
3
7
2
2
2
3
3
2
3
17
1
1
1
1
2
4
14
9
9
9
9
9
20
9
9
9
9
11
13
6
4
4
5
18
7
7
7
7
7
7
8
8
8
6
5
8
6
6
7
5
16
10
10
10
10
11
8
6
1
3
6
5
10
3
3...

output:

? 1 3
? 1 2
! 3
? 1 11
? 1 7
? 3 7
? 5 7
? 5 6
! 6
? 1 2
! 1
? 1 19
? 1 13
? 1 9
? 10 13
? 11 13
! 10
? 1 7
? 3 7
? 5 7
? 3 4
! 3
? 1 3
? 2 3
! 2
? 1 19
? 1 13
? 1 9
? 5 9
? 1 4
? 1 3
? 1 2
! 3
? 1 2
! 1
? 1 15
? 7 15
? 11 15
? 7 10
? 8 10
? 8 9
! 9
? 1 14
? 1 9
? 1 5
? 1 3
? 4 5
! 4
? 1 16
? 1 11
?...

result:

wrong answer Wrong prediction (test case 38)