QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599347#8939. PermutationzookeeperML 0ms0kbC++141.4kb2024-09-29 03:37:052024-09-29 03:37:05

Judging History

This is the latest submission verdict.

  • [2024-09-29 03:37:05]
  • Judged
  • Verdict: ML
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-29 03:37:05]
  • Submitted

answer

#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int query(int L, int R) {
    if (L == R) {
        return L;
    }
    cout << "? " << L << ' ' << R << endl;
    int res;
    cin >> res;
    if (L + 1 == R) {
        return res == L ? R : L;
    }
    while (true) {
        if (L == R) {
            return L;
        }
        if (res - L < R - res) {
            // Query right
            int mid = (res + R) / 2;
            cout << "? " << res << ' ' << mid << endl;
            int res2;
            cin >> res2;
            if (res2 == res) {
                R = mid;
                if (res + 1 == R) {
                    return R;
                }
                continue;
            }
            return query(mid + 1, R);
        }
        // Query left
        int mid = (L + res) / 2;
        cout << "? " << mid << ' ' << res << endl;
        int res2;
        cin >> res2;
        if (res2 == res) {
            L = mid;
            if (L + 1 == res) {
                return L;
            }
            continue;
        }
        return query(L, mid - 1);
    }
}


void solve() {
    int N;
    cin >> N;
    int ans = query(1, N);
    cout << "! " << ans << endl;
}

int main() {
    fastio;
    int T;
    cin >> T;
    for (;T>0;T--) {
        solve();
    }
}

詳細信息

Test #1:

score: 0
Memory Limit Exceeded

input:

3
5
3
2

output:

? 1 5
? 2 3
! 1

result: