QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541724#8939. Permutationucup-team1264#WA 1ms3600kbC++202.2kb2024-08-31 20:42:102024-08-31 20:42:12

Judging History

This is the latest submission verdict.

  • [2024-08-31 20:42:12]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3600kb
  • [2024-08-31 20:42:10]
  • Submitted

answer

// https://www.youtube.com/watch?v=R0P_f0gXXqs
// I could feel your heartbeat
// I could feel somewhere you’re looking down
// ‘Cause it’s you who I’m loving
// And it’s you that I want in need

#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;

#define int i64
int query(int l, int r) {
    if (l == r) return -1;
    cout << "? " << l << " " << r << endl;
    cin >> l; return l;
}
int answer(int x) {
    cout << "! " << x << endl;
    return x;
}
// [5, 10, 8, 17, 19, 9, 18, 4, 2, 3, 15, 16, 14, 13, 12, 11, 1, 6, 7, 20]
void solve() {
    int n; cin >> n;
    int i = query(1, n);
    if (n == 2) {
        if (i == 1) answer(2);
        else answer(1);
        return;
    }
    int left;
    if (i - 1 < n - i) left = query(1, i) == i;
    else left = query(i, n) != i;
    int l, r;
    if (left) l = 1, r = i - 1;
    else l = i + 1, r = n;
    int ll = i, lr = i, lv = i;
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_real_distribution<double> dist(0, 1);
    while (l < r) {
        if (dist(rng) < 0.5) {
            int i = query(l, r);
            int left;
            if (i - l < r - i) left = query(l, i) == i;
            else left = query(i, r) != i;
            if (left) r = i - 1;
            else l = i + 1;
            ll = i, lr = i, lv = i;
        }
        int m = (l + r) / 2;
        if (lr < l) {
            int tv = query(ll, m);
            if (tv == lv) {
                r = m;
            } else {
                ll = tv, lr = m, lv = tv;
                l = m + 1;
            }
        } else {
            int tv = query(m, lr);
            if (tv == lv) {
                l = m + 1;
            } else {
                ll = m + 1, lr = tv, lv = tv;
                r = m;
            }
        }
    }
    answer(l);
}
#undef int

// Make bold hypotheses and verify carefully
int main() {
    // cin.tie(nullptr);
    // ios::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    };
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3600kb

input:

3
5
3
3
5
5

output:

? 1 5
? 3 5
? 4 5
? 4 5
! 5

result:

wrong answer Wrong prediction (test case 1)