QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#652827#8939. PermutationYoshinow2001#RE 0ms0kbC++201.7kb2024-10-18 19:11:142024-10-18 19:11:36

Judging History

This is the latest submission verdict.

  • [2024-10-18 19:11:36]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-18 19:11:14]
  • Submitted

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define int long long
int cnt = 0;
int len = 0;
int C = 0;
int L = 0;
int ask(int l , int r){
    if(l == r) return -1;
    cnt++;
    len += r - l + 1;
    assert(cnt <= C);
    assert(len <= L);
    cout <<"? " <<l <<' '<<r <<endl;
    int ret;
    cin >> ret;
    return ret;
}

void answer(int x){
    cout <<"! " << x <<endl;
}
void f(int l , int r);
void g(int l ,int r ,int x);
const double dx = 0.7;
void solve() {
     int n;
     cin >> n;
     L = 3 * n;
     C = ceil(1.5 * log2(n));
     cnt = len = 0;
     f(1 , n);
}

int32_t main(){
    fastio;
    int tc;cin>>tc;
    while(tc--)solve();
    return 0;
}


void f(int l,int r){
    assert(l <= r);
    if(l >= r){
        answer(l);
        return;
    }
    int s = ask(l , r);
    int l1 = s - l;
    int l2 = r - s;
    if(l1 < l2) {
        int x = ask(l , s);
        if(x != s) g(s , r ,s);
        else g(l , s , s);
    }
    else{
        int x = ask(s , r);
        if(x == s) g(s , r ,s);
        else g(l , s , s);
    }
}

void g(int l , int r , int x){
    int len = (r - l + 1) * dx;
    assert(l != r);
    if(r - l + 1 <= 2){
        answer(l ^ r ^ x);
        return;
    }
    if(x == l){
        int s1 = ask(x , x + len);
        if(s1 == x) g(x , x + len ,x);
        else f(x + len + 1, r);
    }
    else{
        int s1 = ask(x - len , x);
        if(s1 == x) g(x - len , x ,x);
        else f(l, x - len - 1);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
5
3
3
3
3

output:

? 1 5
? 3 5
? 3 5
? 3 5

result: