QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#817557#8939. PermutationKKT89WA 1ms3588kbC++202.1kb2024-12-17 03:43:062024-12-17 03:43:07

Judging History

This is the latest submission verdict.

  • [2024-12-17 03:43:07]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3588kb
  • [2024-12-17 03:43:06]
  • 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;
        int second = -1;
        while (l < r) {
            if (second == -1) {
                cout << "? " << l << " " << r << endl;
                cin >> second;
            }
            if (l + 1 == r) {
                if (l == second) {
                    l += 1;
                }
                break;
            }
            int mid = (l + r) / 2;
            if (second <= mid) {
                cout << "? " << l << " " << mid << endl;
                int res;
                cin >> res;
                if (res == second) {
                    r = mid;
                } else {
                    l = mid + 1;
                    int mid2 = (l + r) / 2;
                    cout << "? " << second << " " << mid2 << endl;
                    cin >> res;
                    if (res == second) {
                        r = mid2;
                    } else {
                        l = mid2 + 1;
                    }
                    second = -1;
                }
            } else {
                cout << "? " << mid << " " << r << endl;
                int res;
                cin >> res;
                if (res == second) {
                    l = mid;
                } else {
                    r = mid - 1;
                    int mid2 = (l + r) / 2;
                    cout << "? " << mid2 << " " << second << endl;
                    cin >> res;
                    if (res == second) {
                        l = mid2;
                    } else {
                        r = mid2 - 1;
                    }
                    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: 3588kb

input:

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

output:

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

result:

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