QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666542#8939. Permutationxh_team#WA 61ms3776kbC++201.8kb2024-10-22 18:58:062024-10-22 18:58:17

Judging History

This is the latest submission verdict.

  • [2024-10-22 18:58:17]
  • Judged
  • Verdict: WA
  • Time: 61ms
  • Memory: 3776kb
  • [2024-10-22 18:58:06]
  • 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) * 7 / 10;
    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: 1ms
memory: 3656kb

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: 59ms
memory: 3652kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 61ms
memory: 3720kb

input:

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

output:

? 1 3
? 2 3
! 3
? 1 11
? 1 7
? 4 7
? 4 5
? 6 7
! 6
? 1 2
! 1
? 1 19
? 1 13
? 1 9
? 10 13
? 12 13
? 10 11
! 10
? 1 7
? 4 7
? 1 3
? 2 3
! 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
? 9 12
? 11 12
? 9 10
! 9
? 1 14
? 1 9
? 1 6
? 1 4
? 1 2
? 3 4
! 4
...

result:

ok Correct (10000 test cases)

Test #4:

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

input:

10000
47
23
23
31
2
2
2
1
3
14
8
2
14
13
11
25
6
6
4
13
13
12
15
7
4
2
6
6
9
2
2
2
2
27
27
27
27
27
24
21
20
21
7
7
7
7
7
6
5
43
41
21
7
7
8
3
1
22
6
14
20
20
19
21
34
29
29
25
17
17
18
16
42
20
20
20
20
20
20
20
19

output:

? 1 47
? 1 32
? 11 32
? 1 10
? 1 7
? 1 4
? 1 2
? 3 4
! 4
? 1 14
? 1 9
? 10 14
? 12 14
? 10 11
! 10
? 1 25
? 1 17
? 1 11
? 12 17
? 12 15
? 12 13
? 14 15
! 14
? 1 7
? 1 4
? 5 7
? 5 6
! 5
? 1 9
? 1 6
? 1 4
? 1 2
! 1
? 1 27
? 10 27
? 16 27
? 20 27
? 23 27
? 20 22
? 20 21
! 22
? 1 21
? 1 14
? 1 9
? 4 9
?...

result:

wrong answer Too long queries, n = 42, now length 128 (test case 11)