QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#818637#8939. PermutationKKT89WA 1ms3556kbC++202.5kb2024-12-18 00:24:492024-12-18 00:24:49

Judging History

This is the latest submission verdict.

  • [2024-12-18 00:24:49]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3556kb
  • [2024-12-18 00:24:49]
  • 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;
            }
            if (l + 3 == r) {
                cout << "? " << l << " " << l + 1 << endl;
                int res;
                cin >> res;
                if (res == second) {
                    l = l + l + 1 - second;
                } else {
                    l = l + 2;
                }
                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;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3556kb

input:

3
5
3
3
3
6
6
5
6
3
4
3
3

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3556kb

input:

10000
10
2
2
1
3
5
10
10
10
8
7
10
5
1
5
6
10
4
4
4
4
10
10
6
3
2
10
3
3
5
2
10
1
5
5
9
9
10
1
3
1
6
10
2
4
4
9
8
10
3
3
3
3
10
4
1
7
8
9
10
8
7
8
4
4
10
4
1
5
9
8
10
7
8
7
4
3
10
5
1
7
8
8
10
8
8
8
9
10
2
1
2
7
10
6
6
7
8
10
10
1
3
1
6
10
7
9
7
5
4

output:

? 1 10
? 1 5
? 1 2
? 2 3
? 4 5
! 4
? 1 10
? 6 10
? 8 10
? 7 10
! 6
? 1 10
? 1 5
? 5 7
? 6 7
! 7
? 1 10
? 1 5
? 3 5
? 3 4
! 3
? 1 10
? 6 10
? 3 10
? 1 2
! 1
? 1 10
? 1 5
? 3 5
? 2 3
! 1
? 1 10
? 1 5
? 1 7
? 8 10
? 8 9
! 8
? 1 10
? 1 5
? 1 7
? 6 7
! 7
? 1 10
? 1 5
? 2 7
? 8 10
? 8 9
! 10
? 1 10
? 1 5
...

result:

wrong answer Wrong prediction (test case 20)