QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103987#6394. Turn on the LightHe_Ren#WA 0ms3528kbC++14854b2023-05-08 09:26:042023-05-08 09:26:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-08 09:26:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2023-05-08 09:26:04]
  • 提交

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!