QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858164#8939. Permutationdark_moonWA 4ms3584kbC++141.6kb2025-01-16 14:37:552025-01-16 14:38:45

Judging History

This is the latest submission verdict.

  • [2025-01-16 14:38:45]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 3584kb
  • [2025-01-16 14:37:55]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
// auto IOS = ios::sync_with_stdio(false);
// auto CIN = cin.tie(nullptr);
int t;
int query(int l, int r){
    if(l == r){
        return 0;
    }
    int x;
    cout << "? " << l << " " << r << "\n";
    cout.flush();
    cin >> x;
    return x;
}
signed main(){
    cin >> t;
    while(t --){
        int n;
        cin >> n;
        int l = 1, r = n, p = -1;
        auto get = [](int l, int r, double form){
            // return l + r >> 1;
            int mid = (l + r) * form;
            mid = min(mid, r - 1);
            mid = max(mid, l);
            return mid;
        };
        while(l < r){
            if(p == -1){
                p = query(l, r);
            }
            else{
                int mid = l + r >> 1;
                if(p <= mid){
                    int vmid = get(l, r, 0.618);
                    if(query(l, vmid) == p){
                        r = vmid;
                    }
                    else{
                        l = vmid + 1;
                        p = -1;
                    }
                }
                else{
                    int vmid = get(l, r, 0.382);
                    if(query(vmid + 1, r) == p){
                        l = vmid + 1;
                    }
                    else{
                        r = vmid;
                        p = -1;
                    }
                }
            }
        }
        cout << "! " << l << "\n";
        cout.flush();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 3584kb

input:

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

output:

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

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 42)