QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607196#8939. PermutationUESTC_NLNS#WA 1ms3860kbC++14876b2024-10-03 14:15:262024-10-03 14:15:26

Judging History

This is the latest submission verdict.

  • [2024-10-03 14:15:26]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3860kb
  • [2024-10-03 14:15:26]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
unordered_map<ll,int> mp;
const int N=1e6+5;
void answer(int x)
{
	printf("! %d\n",x);
	fflush(stdout);
	return;
}
int query(int l,int r)
{
	ll id=1ll*l*N+r;
	if(mp.find(id)!=mp.end()) return mp[id];
	int x;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&x);
	mp[id]=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+1,r);
		if(x==y) solve(mid+1,r);
		else solve(l,mid);
	}
	return;
}
int T,n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		solve(1,n);
		mp.clear();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
2
5
6
6
5
3

output:

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

result:

wrong answer Integer 3 violates the range [4, 6] (test case 2)