QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371552 | #6394. Turn on the Light | huangxi# | TL | 0ms | 0kb | C++17 | 653b | 2024-03-30 13:57:54 | 2024-03-30 13:57:55 |
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef long long LL;
const int N=1e3+10,M=510;
int n,m;
pair<int,int>a[N],b[N];
int query(int x){
int cur;
cout<<"? "<<x;
cout.flush();
cin>>cur;
return cur;
}
int main() {
scanf("%d",&n);
int l=1,r=n;
int pre=0;
while(l<=r){
int mid=l+r>>1;
int cur=query(mid);
if(cur==pre){
cout<<"! "<<mid;
cout.flush();
break;
}else if(cur>pre){
l=mid+1;
}else{
r=mid-1;
}
pre=cur;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3
output:
? 2