QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#870949#8939. PermutationthangthangTL 0ms3584kbC++201.2kb2025-01-25 18:37:472025-01-25 18:37:48

Judging History

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

  • [2025-01-25 18:37:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3584kb
  • [2025-01-25 18:37:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

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

int solve(int l, int r, int op){
    if (l == r) return l;
    if (l + 1 == r) return l ^ r ^ qry(l, r);

    if (op == -1){
        int mid = qry(l, r);
        if (mid == l) return solve(l + 1, r, 0);
        if (mid == r) return solve(l, r - 1, 1);
        if (mid - l < r - mid){
            if (qry(l, mid) == mid) return solve(l, mid - 1, 1);
            return solve(mid + 1, r, 0);
        }
        if (qry(mid, r) == mid) return solve(mid + 1, r, 0);
        return solve(l, mid - 1, 1);
    }

    int len = (r - l + 1) / 3 * 2 - 1;
    if (op == 0){
        int mid = l + len;
        if (qry(l - 1, mid) == l - 1) return solve(l, mid, 0);
        return solve(mid + 1, r, -1);
    }

    int mid = r - len;
    if (qry(mid, r + 1) == r + 1) return solve(mid, r, 1);
    return solve(l, mid - 1, -1);
}

void process(){
    int n; cin >> n;
    int ans = solve(1, n, -1);
    cout << "! " << ans << endl;
}

int main(){
    int t; cin >> t; while (t --)
    process();

    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

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

output:

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

result: