QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556386#8939. Permutationucup-team3519#TL 1ms3704kbC++201.4kb2024-09-10 17:31:172024-09-10 17:31:20

Judging History

This is the latest submission verdict.

  • [2024-09-10 17:31:20]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3704kb
  • [2024-09-10 17:31:17]
  • 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);
    if (x == r || x == l) {
        return subsolve(l, r, x);
    } else {
        if (query(l, x) == x) {
            return subsolve(l, x, x);
        } else {
            return subsolve(x, 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) - 2);
    if (x == l) {
        int p = query(l, l + d);
        if (p == x) {
            return subsolve(l, l + d, x);
        } else {
            return solve(l + d + 1, r);
        }
    } else {
        int p = query(r - d, r);
        if (p == x) {
            return subsolve(r - d, r, x);
        } else {
            return solve(l, r - d - 1);
        }
    }
}

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

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

        solve(1, n);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

10000
10
2
1
2
2
2

output:

? 1 10
? 1 2
? 2 8
? 2 6
? 2 5
? 2 4

result: