QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#538375#8939. Permutationucup-team3555#WA 3ms3680kbC++20839b2024-08-31 11:01:192024-08-31 11:01:19

Judging History

This is the latest submission verdict.

  • [2024-08-31 11:01:19]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3680kb
  • [2024-08-31 11:01:19]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e6+3;
ll n;
int Ask(int l,int r)
{
	cout<<"? "<<l<<" "<<r<<endl;
	int x;cin>>x;
	return x;
	//return query(l,r);
}
int Sol(int l,int r)
{
	if(l==r)return l;
	int p=Ask(l,r),op=0;
	if(l+1==r)return p==l?l+1:l;
	if(p-l<=r-p)op=(p==l||Ask(l,p)!=p)?1:0;
	else op=(p==r||Ask(p,r)!=p)?0:1;
	if(!op)
	{
		int kl=l,kr=p-1;
		while(kl<kr)
		{
			int mi=(kl+kr)/2+1;
			if(Ask(mi,p)==p)kl=mi;
			else return Sol(l,mi-1);
		}
		return p-1;
	}
	else
	{
		int kl=p+1,kr=r;
		while(kl<kr)
		{
			int mi=(kl+kr)/2;
			if(Ask(p,mi)==p)kr=mi;
			else return Sol(mi+1,r); 
		}
		return p+1;
	}
}
void Solve()
{
	cin>>n;
	int x=Sol(1,n);
	cout<<"! "<<x<<endl; 
}
int main()
{
	int T;cin>>T;
	while(T--)Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3ms
memory: 3604kb

input:

10000
10
2
1
2
2
3

output:

? 1 10
? 1 2
? 2 6
? 2 4
? 2 3
? 4 10

result:

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