QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541630#8939. Permutationucup-team3734#WA 6ms3612kbC++231.3kb2024-08-31 20:16:122024-08-31 20:16:14

Judging History

This is the latest submission verdict.

  • [2024-08-31 20:16:14]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 3612kb
  • [2024-08-31 20:16:12]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double lf;

int ask(int l, int r) {
    cout << "? " << l << " " << r << endl;
    int res;
    cin >> res;
    return res;
}

void answer(int x) {
    cout << "! " << x << endl;
}

void go(int l, int r, optional<int> pos) {
    if (l == r) {
        answer(l);
        return;
    }
    if (!pos.has_value()) {
        pos = ask(l, r);
    }
    if (l + 1 == r) {
        answer(*pos == l ? r : l);
        return;
    }
    int len = (int) ceil((r - l + 1) * 0.6135117904356906);
    int m = (l + r) / 2;
    if (pos <= m) {
        m = l + len - 1;
        int x = ask(l, m);
        if (x == *pos) {
            go(l, m, x);
        } else {
            go(m + 1, r, nullopt);
        }
    } else {
        m = r - len + 1;
        int x = ask(m, r);
        if (x == *pos) {
            go(m, r, x);
        } else {
            go(l, m - 1, nullopt);
        }
    }
}

void solve() {
    int n;
    cin >> n;
    go(1, n, nullopt);
}

signed main() {
#ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 3556kb

input:

10000
10
2
2
2
2
3
10
10
10
10
7
10
5
5
5
4
10
4
4
4
4
4

output:

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

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 4)