QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620078#8939. Permutationzzpcd#WA 3ms3728kbC++201.1kb2024-10-07 16:31:062024-10-07 16:31:07

Judging History

This is the latest submission verdict.

  • [2024-10-07 16:31:07]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3728kb
  • [2024-10-07 16:31:06]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n;
const double k = 0.629;
int ask(int l, int r) {
    if(l == r) return -1;
    cout << "? " << l << ' ' << r << endl;
    int x;
    cin >> x;
    return x;
}
void answer(int x) {
    cout << "! " << x << endl;
    return;
}
void solve(int l, int r, int sec = -1) {
    if(l == r) {
        answer(l);
        return;
    }
    if(sec == -1) sec = ask(l, r);
    if(l + 1 == r) {
        answer(l == sec ? r : l);
        return;
    }
    int mid = (r - l + 1) * k;
    if(l + mid - 1 >= sec) {
        mid = l + mid - 1;
        int u = ask(l, mid);
        if(u == sec) {
            return solve(l, mid, sec);
        } else return solve(mid + 1, r, -1);
    } else {
        mid = r - mid + 1;
        int u = ask(mid, r);
        if(u == sec) {
            return solve(mid, r, sec);
        } else return solve(l, mid - 1, -1);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) {
        int n;
        cin >> n;
        solve(1, n);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3684kb

input:

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

output:

? 1 5
? 1 3
? 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
Wrong Answer
time: 3ms
memory: 3728kb

input:

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

output:

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

result:

wrong answer Wrong prediction (test case 4)