QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607498#8939. PermutationUESTC_Snow_Halation#TL 68ms10396kbC++142.8kb2024-10-03 15:04:112024-10-03 15:04:13

Judging History

This is the latest submission verdict.

  • [2024-10-03 15:04:13]
  • Judged
  • Verdict: TL
  • Time: 68ms
  • Memory: 10396kb
  • [2024-10-03 15:04:11]
  • Submitted

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define FOR() ll le=e[u].size();for(ll i=0;i<le;i++)
#define QWQ cout<<"QwQ\n";
#define ll long long
#include <vector>
#include <queue>
#include <map>

using namespace std;
const ll N=1201010;
const ll qwq=303030;
const ll inf=0x3f3f3f3f;

inline ll read() {
    ll sum = 0, ff = 1; char c = getchar();
    while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
    while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
    return sum * ff;
}

int T,n;
int f[N],fen[N];
int ans;
int cnt = 0;

void ask(int l,int r) {
    cnt++;
    if(cnt>(ll)ceil((double)(1.5*log2(n)))) cout<<cnt/0;
    cout<<"? "<<l<<" "<<r<<"\n";
    fflush(stdout);
}

void DFS(int cl,int wei,int l,int r) {
    int len = r-l+1;

    if(len<=1) { cout<<wei/0; }

    if(len==2) {
        ask(l,r);
        int xia = read();
        if(xia==l) ans = r;
        else       ans = l;
        return ;
    }

    if(cl==0) {
        ask(l,r);
        wei = read();
    }

    if(len==3) {
        if(wei==l) {
            ask(l,l+1);
            int xia = read();
            if(xia==l) ans = l+1;
            else       ans = r;
        }
        else if(wei==l+1) {
            ask(l,l+1);
            int xia = read();
            if(xia==l) ans = r;
            else       ans = l;
        }
        else {
            ask(l+1,r);
            int xia = read();
            if(xia==r) ans = l+1;
            else       ans = l;
        }
        return ;
    }


    int mid = l+fen[len]-1;
    if(wei<=mid) {
        ask(l,mid);
        int xia = read();
        if(xia==wei) DFS(1,wei,l,mid);
        else         DFS(0,0,mid+1,r);
    }
    else {
        mid = r-fen[len]+1;
        ask(mid,r);
        int xia = read();
        if(xia==wei) DFS(1,wei,mid,r);
        else         DFS(0,0,l,mid-1);
    }
}

int main() {
    f[1] = inf;
    f[2] = 1; fen[2] = 1;
    f[3] = 1; fen[3] = 1;
    f[4] = 2; fen[4] = 2;
    f[5] = 3; fen[5] = 3;
    for(int i=6;i<=3000;i++) {
        f[i] = inf;
        int mid = (i+1)/2;
        for(int j=mid;j<=i-2;j++) {
            int need = max(f[j]+1,f[i-j]+1+1);
            if(need <= f[i]) f[i] = need, fen[i] = j;
        }
        // if(i<=1000) cout<<i<<" f = "<<f[i]<<" fen = "<<fen[i]<<"\n";
        if(f[i]>(ll)ceil((double)(1.5*log2(i)))) while(1) {i++;}
    }
    for(int i=3001;i<=N-10;i++) fen[i] = i*2/3;

    T = read();
    while(T--) {
        n = read();
        cnt = 0;
        DFS(0,0,1,n);
        cout<<"! "<<ans<<"\n";
        fflush(stdout);
    }
    return 0;
}

/*

3
2 3
1 2
2 2
4 5 100

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

*/

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 10396kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 68ms
memory: 9508kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Time Limit Exceeded

input:

10000
3
1
2
11
5
5
5
4
7
2
2
19
3
3
3
4

output:

? 1 3
? 1 2
! 3
? 1 11
? 1 7
? 4 7
? 4 5
? 6 7
! 6
? 1 2
! 1
? 1 19
? 1 17
? 1 11
? 1 7
? 8 11

result: