QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666544#8939. Permutationxh_team#WA 65ms3748kbC++201.8kb2024-10-22 18:58:532024-10-22 18:58:55

Judging History

This is the latest submission verdict.

  • [2024-10-22 18:58:55]
  • Judged
  • Verdict: WA
  • Time: 65ms
  • Memory: 3748kb
  • [2024-10-22 18:58:53]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2014;

mt19937 rnd(time(0));

int a[] = {-1, 4, 7, 2, 6, 5, 1, 9};

int ask(int l, int r) {
    cout << '?' << ' ' << l << ' ' << r << endl;
    int x;
    cin >> x;
    return x;


    // int fi = -1, se = -1;
    // for (int i = l; i <= r; i++) {
    //     fi = max(fi, a[i]);
    // }
    // int x = -1;
    // for (int i = l; i <= r; i++) {
    //     if (a[i] != fi && a[i] > se) {
    //         se = a[i];
    //         x = i;
    //     }
    // }
    // return x;
}

int n, p, ans;
void dfs(int l, int r) {
    if (r - l == 1) {
        ans = l + r - p;
        return;
    }
    if (r - l == 2) {
        if (p == l) {
            int q = ask(l + 1, r);
            ans = l + 1 + r - q;
        } else if (p == r) {
            int q = ask(l, l + 1);
            ans = l + l + 1 - q;
        } else {
            int q = ask(l, l + 1);
            if (p == q) {
                ans = l;
            } else {
                ans = r;
            }
        }
        return;
    }

    int len23 = (r - l + 1) * 8 / 11;
    if (p <= l + len23 - 1) {
        int q = ask(l, l + len23 - 1);
        if (p == q) {
            dfs(l, l + len23 - 1);
        } else {
            p = ask(l + len23, r);
            dfs(l + len23, r);
        }
    } else {
        int q = ask(r - len23 + 1, r);
        if (p == q) {
            dfs(r - len23 + 1, r);
        } else {
            p = ask(l, r - len23);
            dfs(l, r - len23);
        }
    }

}

void solve() {
    cin >> n;
    p = ask(1, n);
    dfs(1, n);
    cout << '!' << ' ' << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);

    int tt;
    cin >> tt;
    while (tt--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 65ms
memory: 3748kb

input:

10000
10
2
2
2
3
5
10
10
10
10
8
7
10
5
5
1
6
10
4
4
4
4
4
10
10
6
3
2
10
3
3
3
3
2
10
1
5
9
9
10
1
1
3
6
10
2
4
9
8
10
3
3
3
1
5
10
4
7
8
9
10
8
7
1
2
10
4
1
9
8
10
7
7
7
7
6
10
5
1
8
10
10
8
8
6
9
10
2
2
1
7
10
6
4
10
8
10
1
1
3
6
10
7
7
7
5
4
10
7
7
7
5
4
10
3
4
10
8
10
4
4
4
4
3
10
8
7
2
2
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
? 1 7
? 1 5
? 6 7
! 7
? 1 10
? 1 7
? 1 5
? 3 5
? 3 4
! 3
? 1 10
? 4 10
? 1 3
? 1 2
! 1
? 1 10
? 1 7
? 1 5
? 1 3
? 1 2
! 1
? 1 10
? 1 7
? 8 10
? 8 9
! 8
? 1 10
? 1 7
? 1 5
? 6 7
! 7
? 1 10
? 1 7
? 8 10
? 8 9
! 10
? 1 10
?...

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 3672kb

input:

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

output:

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

result:

wrong answer Too long queries, n = 20, now length 61 (test case 88)