QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688809#8939. Permutationlqh2024WA 0ms3840kbC++201.6kb2024-10-30 13:42:072024-10-30 13:42:07

Judging History

This is the latest submission verdict.

  • [2024-10-30 13:42:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3840kb
  • [2024-10-30 13:42:07]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 rng(time(0));
template <class T, class ... A> void debug(T t, A ... a) {
    cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n";
}

void QAQ() {
    int n;
    cin >> n;

    vector<int> a(n + 1);

    auto query = [&](int l, int r, int x = -1) {
        cout << "? " << l << " " << r << endl;
        return cin >> x, x;
    };
    
    auto answer = [&](int n) {
        cout << "! " << n << endl;
    };

    int lst = query(1, n);

    auto F = [&](auto && self, int l, int r) {
        if (l >= r) return answer(l);
        if (l + 1 == r) {
            if (l == lst) return answer(r);
            else return answer(l);
        }
        int m = l + 0.6 * (r - l), tmp = rng() % 2;
        if (m == r) m--;
        if (l + 2 == r) {
            m = l;
            tmp = query(m + 1, r);
            if (l == lst) {
                if (tmp == r) return answer(m + 1);
                else return answer(r);
            } else {
                if (tmp == lst) return answer(tmp == r ? r - 1 : r);
                else return answer(l);
            }
        }
        tmp = query(l, m);
        if (tmp == lst) {
            lst = tmp;
            return self(self, l, m);
        } else {
            int t = query(m + 1, r);
            lst = t;
            return self(self, m + 1, r);
        }
    };

    F(F, 1, n);
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (cout << fixed << setprecision(12); t--; QAQ());
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3840kb

input:

3
5
3
2
5
6
6
3
5

output:

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

result:

wrong answer Wrong prediction (test case 2)