QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607133#8939. PermutationUESTC_NLNS#WA 1ms3920kbC++14716b2024-10-03 14:01:302024-10-03 14:01:30

Judging History

This is the latest submission verdict.

  • [2024-10-03 14:01:30]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3920kb
  • [2024-10-03 14:01:30]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
void answer(int x)
{
	printf("! %d\n",x);
	fflush(stdout);
	return;
}
int query(int l,int r)
{
	int x;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&x);
	return x;
}
void solve(int l,int r)
{
	if(l==r)
	{
		answer(l);
		return;
	}
	int mid=(l+r)>>1,x=query(l,r),y;
	if(l+1==r)
	{
		if(x==l) answer(r);
		else answer(l);
		return;
	}
	if(x<=mid)
	{
		y=query(l,mid);
		if(x==y) solve(l,mid);
		else solve(mid+1,r);
	}
	else
	{
		y=query(mid,r);
		if(x==y) solve(mid,r);
		else solve(l,mid-1);
	}
	return;
}
int T,n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		solve(1,n);
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3920kb

input:

3
5
3
2
5
6
6
3
1
4
3
3
3

output:

? 1 5
? 1 3
? 4 5
! 4
? 1 6
? 3 6
? 1 2
! 2
? 1 4
? 2 4
? 2 4
? 2 3

result:

wrong answer Too many queries , n = 4 , now_q 4 (test case 3)