QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737918#8239. Mysterious TreeKiritoXDWA 1ms3820kbC++201.5kb2024-11-12 17:10:042024-11-12 17:10:04

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 17:10:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-11-12 17:10:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=1e5+7, mod=1e9+7;

int n;

void solve(){
    cin>>n;
    int len=1;
    int l=-1,r=-1;
    for(int i=1;i<=n;i+=2){
        printf("? %d %d\n",i,i+1);
        int x;
        cin>>x;
        if(x){
            l=i,r=i+1;
            break;
        }
    }
    if(n&1){
        printf("? %d %d\n",n,n-1);
        int x;
        cin>>x;
        if(x){
            l=n-1,r=n;
        }
    }
    if(l==-1&&r==-1){
        printf("! 1");
        cout<<endl;
    }
    else{
        int t1,t2,t3,x1,x2;
        if(l==1)t1=n;
        else t1=l-1;
        if(r==n)t2=1;
        else t2=r+1;
        printf("? %d %d\n",l,t1);
        cin>>x1;
        printf("? %d %d\n",r,t2);
        cin>>x2;
        if(x1){
            printf("? %d %d\n",l,t1-1);
            cin>>x1;
            if(x1){
                printf("! 2");
                cout<<endl;
            }
            else {
                printf("! 1");
                cout<<endl;
            }
        }
        if(x2){
            printf("? %d %d\n",r,t2+1);
            cin>>x2;
            if(x2){
                printf("! 2");
                cout<<endl;
            }
            else {
                printf("! 1");
                cout<<endl;
            }
        }
    }
}

int main(){
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

详细

Test #1:

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

input:

2
4
1
0
1
0
4
0
1
1
0
1

output:

? 1 2
? 1 4
? 2 3
? 2 4
! 1
? 1 2
? 3 4
? 3 2
? 4 1
? 3 1
! 2

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3768kb

input:

87
13
0
0
0
0
0
1
1
1
0
1
15
0
0
0
0
0
0
1
0
1
0
1
7
0
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 12
? 12 11
? 13 1
? 12 10
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 15 14
? 13 12
? 14 15
? 13 11
! 2
? 1 2
? 3 4
? 5 6
? 7 8

result:

wrong answer Integer 8 violates the range [1, 7] (test case 3)