QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619899#8939. Permutationzzpcd#WA 3ms3652kbC++201.1kb2024-10-07 15:50:282024-10-07 15:50:30

Judging History

This is the latest submission verdict.

  • [2024-10-07 15:50:30]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3652kb
  • [2024-10-07 15:50:28]
  • 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 == k) {
        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);
    }
}

詳細信息

Test #1:

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

input:

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

output:

? 1 5
? 3 5
? 3 4
! 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: 3556kb

input:

10000
10
2
9
2
3
1

output:

? 1 10
? 5 10
? 1 4
? 3 4
? 1 2
! 2

result:

wrong answer Wrong prediction (test case 1)