QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870948#8939. PermutationthangthangTL 0ms0kbC++201.2kb2025-01-25 18:36:072025-01-25 18:36:17

Judging History

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

  • [2025-01-25 18:36:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2025-01-25 18:36:07]
  • 提交

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;
    cout << "! " << solve(1, n, -1) << endl;
}

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
5

output:

! ? 1 5

result: