QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#652765#8939. PermutationYoshinow2001#WA 1ms3628kbC++201.5kb2024-10-18 19:06:112024-10-18 19:06:19

Judging History

This is the latest submission verdict.

  • [2024-10-18 19:06:19]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3628kb
  • [2024-10-18 19:06:11]
  • 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 ask(int l , int r){
    if(l == r) return -1;
    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 int N = 3;
const int M = 5;
void solve() {
     int n;
     cin >> n;
     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) * N / M - 1;
    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: 3584kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

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

input:

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

output:

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

result:

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