QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#652819#8939. PermutationYoshinow2001#RE 1ms3788kbC++201.7kb2024-10-18 19:10:502024-10-18 19:11:11

Judging History

This is the latest submission verdict.

  • [2024-10-18 19:11:11]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3788kb
  • [2024-10-18 19:10:50]
  • 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.55;
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);
    }
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Runtime Error

input:

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

output:

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

result: