QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554950#8939. Permutationdonghanwen1225WA 32ms3812kbC++141.1kb2024-09-09 18:17:422024-09-09 18:17:43

Judging History

This is the latest submission verdict.

  • [2024-09-09 18:17:43]
  • Judged
  • Verdict: WA
  • Time: 32ms
  • Memory: 3812kb
  • [2024-09-09 18:17:42]
  • 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);
		if(res==l) sol(l,mid,l);
		else sol(mid+1,r,0);
	}
	else if(k==r)
	{
		int mid=(l+r)/2;
		int res=qry(mid+1,r);
		if(res==r) sol(mid+1,r,r);
		else sol(l,mid,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: 3812kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 32ms
memory: 3748kb

input:

10000
10
2
1
2
2
3
10
10
10
9
7
7
10
5
1
5
6
10
4
4
4
10
10
6
3
3
2
10
3
3
2
10
1
5
9
10
9
10
1
3
8
8
8
10
2
1
4
9
9
10
3
1
3
3
10
4
1
7
8
9
10
8
9
7
1
2

output:

? 1 10
? 1 2
? 2 6
? 2 4
? 2 3
! 4
? 1 10
? 6 10
? 9 10
? 6 8
? 6 7
! 6
? 1 10
? 1 5
? 5 7
? 5 6
! 7
? 1 10
? 1 4
? 3 4
! 3
? 1 10
? 6 10
? 1 5
? 1 3
? 2 3
! 1
? 1 10
? 1 3
? 2 3
! 1
? 1 10
? 1 5
? 6 10
? 9 10
? 8 9
! 8
? 1 10
? 1 5
? 6 10
? 6 8
? 7 8
! 7
? 1 10
? 1 2
? 2 6
? 7 10
? 9 10
! 10
? 1 10...

result:

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