QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103987 | #6394. Turn on the Light | He_Ren# | WA | 0ms | 3528kb | C++14 | 854b | 2023-05-08 09:26:04 | 2023-05-08 09:26:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e6 + 5;
bool vis[MAXN];
int ask(int x)
{
vis[x] = 1;
printf("? %d\n",x);
fflush(stdout);
int res;
scanf("%d",&res);
return res;
}
void answer(int x)
{
printf("! %d\n",x);
fflush(stdout);
exit(0);
}
int main(void)
{
int n;
scanf("%d",&n);
int lst = ask(1);
if(lst == 0) answer(1);
int pos = 1;
int l = 2, r = n;
while(l < r)
{
int mid = (l+r)>>1;
int cur = ask(mid);
if(cur == lst) answer(mid);
if(cur > lst) r = mid-1;
else l = mid+1;
if(l == r) answer(l);
lst = cur;
if(lst == 0)
{
while(vis[pos]) ++pos;
cur = ask(pos);
if(cur == lst) answer(pos);
lst = cur;
while(vis[l]) ++l;
}
}
answer(l);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
3 1 2
output:
? 1 ? 2 ! 2
result:
wrong answer Wrong favorite light!