QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#538398#8939. Permutationucup-team3555#WA 2ms3564kbC++20893b2024-08-31 11:20:252024-08-31 11:20:28

Judging History

This is the latest submission verdict.

  • [2024-08-31 11:20:28]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3564kb
  • [2024-08-31 11:20:25]
  • 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,nb=l;
		while(kl<=kr)
		{
			int mi=kl+(kr-kl+1)*(1-0.618);
			if(Ask(mi,p)==p)nb=mi,kl=mi+1;
			else return Sol(nb,mi-1);
		}
		return p-1;
	}
	else
	{
		int kl=p+1,kr=r,nb=r;
		while(kl<=kr)
		{
			int mi=kl+(kr-kl+1)*(1-0.618);
			if(Ask(p,mi)==p)nb=mi,kr=mi-1;
			else return Sol(mi+1,nb); 
		}
		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: 3540kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3564kb

input:

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

output:

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

result:

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