QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818636#8939. PermutationKKT89WA 1ms3728kbC++202.1kb2024-12-18 00:21:012024-12-18 00:21:01

Judging History

This is the latest submission verdict.

  • [2024-12-18 00:21:01]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3728kb
  • [2024-12-18 00:21:01]
  • Submitted

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int l = 1, r = n + 1;
        int second = -1;
        while (l + 1 < r) {
            if (second == -1) {
                cout << "? " << l << " " << r - 1 << endl;
                cin >> second;
            }
            if (l + 2 == r) {
                if (l == second) {
                    l += 1;
                }
                break;
            }
            int mid = (l + r) / 2;
            if (second < mid) {
                cout << "? " << l << " " << mid - 1 << endl;
                int res;
                cin >> res;
                if (res == second) {
                    r = mid;
                } else {
                    l = mid;
                    int mid2 = (l + r) / 2;
                    cout << "? " << second << " " << mid2 - 1 << endl;
                    cin >> res;
                    if (res == second) {
                        r = mid2;
                    } else {
                        l = mid2;
                    }
                    second = -1;
                }
            } else {
                cout << "? " << mid << " " << r - 1 << endl;
                int res;
                cin >> res;
                if (res == second) {
                    l = mid;
                } else {
                    r = mid;
                    int mid2 = (l + r) / 2;
                    cout << "? " << mid2 << " " << second << endl;
                    cin >> res;
                    if (res == second) {
                        l = mid2;
                    } else {
                        r = mid2;
                    }
                    second = -1;
                }
            }
        }
        cout << "! " << l << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
3

output:

? 1 5
? 3 5
? 3 3

result:

wrong answer Integer 3 violates the range [4, 5] (test case 1)