QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737946 | #8239. Mysterious Tree | KiritoXD | TL | 1ms | 3836kb | C++20 | 1.5kb | 2024-11-12 17:14:08 | 2024-11-12 17:14:09 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3836kb
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
Time Limit Exceeded
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 1 0 1 1 15 0 0 0 1 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 6 ? 6 5 ? 7 1 ? 7 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 15 14 ? 7 6 ? 8 9