QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554955#8939. Permutationdonghanwen1225WA 41ms3876kbC++141.1kb2024-09-09 18:19:402024-09-09 18:19:41

Judging History

This is the latest submission verdict.

  • [2024-09-09 18:19:41]
  • Judged
  • Verdict: WA
  • Time: 41ms
  • Memory: 3876kb
  • [2024-09-09 18:19:40]
  • Submitted

answer

#include<iostream>
#include<cstdio>
using namespace std;
int t,n;
int qry(int l,int r)
{
	printf("? %d %d\n",l,r);fflush(stdout);
	int x;scanf("%d",&x);return x;
}
void ans(int x){printf("! %d\n",x);fflush(stdout);}
void sol(int l,int r,int k)
{
	if(l==r){ans(l);return;}
	if(r-l==1)
	{
		if(k) ans(l+r-k);
		else ans(l+r-qry(l,r));
		return;
	}
	if(r-l==2)
	{
		if(!k) k=qry(l,r);
		if(k==l) ans(qry(l,l+1)==l+1?l+2:l+1);
		if(k==l+1) ans(qry(l,l+1)==l?l+2:l);
		if(k==l+2) ans(qry(l+1,l+2)==l+1?l:l+1);
		return;
	}
	if(!k) k=qry(l,r);
	if(k==l)
	{
		int mid=(l+r)/2;
		int res=qry(l,mid+1);
		if(res==l) sol(l,mid+1,l);
		else sol(mid+2,r,0);
	}
	else if(k==r)
	{
		int mid=(l+r)/2;
		int res=qry(mid,r);
		if(res==r) sol(mid,r,r);
		else sol(l,mid-1,0);
	}
	else
	{
		int res=0;
		if(2*k<=l+r)
		{
			res=qry(l,k);
			if(res==k) sol(l,k,k);
			else sol(k,r,k);
		}
		else
		{
			res=qry(k,r);
			if(res==k) sol(k,r,k);
			else sol(l,k,k);
		}
	}
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		sol(1,n,0);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3876kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 3788kb

input:

10000
10
2
1
2
2
2

output:

? 1 10
? 1 2
? 2 7
? 2 5
? 2 4
? 2 3

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 1)