QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#539748#8939. Permutationucup-team055#WA 3ms3700kbC++201.4kb2024-08-31 15:34:542024-08-31 15:34:56

Judging History

This is the latest submission verdict.

  • [2024-08-31 15:34:56]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3700kb
  • [2024-08-31 15:34:54]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define all(p) p.begin(),p.end()
using ll = long long;
template<class T> bool chmin(T &a, T b){return (a > b ? a = b, 1 : 0);}
template<class T> bool chmax(T &a, T b){return (a < b ? a = b, 1 : 0);}

const ll A = 3236067;
const ll B = 2000000;

void solve(){
    int N;
    cin >> N;
    auto ask = [&](int l, int r) -> int {
        cout << "? " << l + 1 << " " << r << endl;
        int res;
        cin >> res;
        return res - 1;
    };
    auto f = [&](auto self, ll l, ll r, int a = -1) -> int {
        ll len = r - l;
        if (len == 1) return l;
        if (a != -1 && len == 2){
            return (l ^ a ^ (l + 1));
        }
        if (a == -1){
            return self(self, l, r, ask(l, r));
        }
        ll diff = (len * B + A) / A;
        if (a < l + diff){
            int tmp = ask(l, l + diff);
            if (tmp == a) return self(self, l, l + diff, a);
            return self(self, l + diff, r, -1);
        }
        else{
            int tmp = ask(r - diff, r);
            if (tmp == a) return self(self, r - diff, r, a);
            return self(self, l, r - diff, -1);
        }
    };
    int ans = f(f, 0, N);
    cout << "! " << ans + 1 << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t ;
    cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3700kb

input:

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

output:

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

result:

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