QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556415#8939. Permutationucup-team3519#WA 2ms3696kbC++171.2kb2024-09-10 17:55:412024-09-10 17:55:42

Judging History

This is the latest submission verdict.

  • [2024-09-10 17:55:42]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3696kb
  • [2024-09-10 17:55:41]
  • Submitted

answer

#include <bits/stdc++.h>

using real = long double;
constexpr real ALPHA = 0.618;

int query(int l, int r) {
    std::cout << "? " << l << ' ' << r << std::endl;
    int x;
    std::cin >> x;
    return x;
}

void subsolve(int l, int r, int x);

void solve(int l, int r) {
    if (l == r) {
        std::cout << "! " << l << std::endl;
        return;
    }
    int x = query(l, r);
    return subsolve(l, r, x);
}

void subsolve(int l, int r, int x) {
    if (r - l + 1 <= 2) {
        std::cout << "! " << l + r - x << std::endl;
        return;
    }

    int d = (r - l + 1) * ALPHA + 0.5;
    d = std::min(d, (r - l + 1) - 1);

    if (x <= l + d) {
        int p = query(l, l + d - 1);
        if (p == x) {
            return subsolve(l, l + d - 1, x);
        } else {
            return solve(l + d, r);
        }
    } else {
        int p = query(r - d + 1, r);
        if (p == x) {
            return subsolve(r - d + 1, r, x);
        } else {
            return solve(l, r - d);
        }
    }
}

int main() {
    int t;
    std::cin >> t;

    while (t--) {
        int n;
        std::cin >> n;

        solve(1, n);
    }
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3636kb

input:

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

output:

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

result:

wrong answer Wrong prediction (test case 5)