QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554073#8939. PermutationCharizard2021WA 1ms3612kbC++141.2kb2024-09-09 04:48:292024-09-09 04:48:30

Judging History

This is the latest submission verdict.

  • [2024-09-09 04:48:30]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3612kb
  • [2024-09-09 04:48:29]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int solve(int low, int high, int cur){
    if(low == high){
        return low;
    }
    if(cur == INT_MIN){
        cout << "? " << low << " " << high << "\n";
        cout.flush();
        cin >> cur;
    }
    if(low + 1 == high){
        if(cur == low){
            return high;
        }
        else{
            return low;
        }
    }
    int mid = (2 * low + high)/3;
    if(cur <= mid){
        cout << "? " << low << " " << mid << "\n";
        cout.flush();
        int x;
        cin >> x;
        if(x == cur){
            return solve(low, mid, x);
        }
        else{
            return solve(mid + 1, high, INT_MIN);
        }
    }
    else{
        cout << "? " << mid + 1 << " " << high << "\n";
        cout.flush();
        int x;
        cin >> x;
        if(x == cur){
            return solve(mid + 1, high, x);
        }
        else{
            return solve(low, mid, INT_MIN);
        }
    }
}
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int res = solve(1, n, INT_MIN);
        cout << "! " << res << "\n";
        cout.flush();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3612kb

input:

3
5
3
3

output:

? 1 5
? 3 5
? 3 3

result:

wrong answer Integer 3 violates the range [4, 5] (test case 1)