QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607559#8939. PermutationUESTC_NLNSWA 24ms3960kbC++14917b2024-10-03 15:19:552024-10-03 15:19:56

Judging History

This is the latest submission verdict.

  • [2024-10-03 15:19:56]
  • Judged
  • Verdict: WA
  • Time: 24ms
  • Memory: 3960kb
  • [2024-10-03 15:19:55]
  • Submitted

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
map<pii,int> mp;
const int N=1e6+5;
void answer(int x)
{
	printf("! %d\n",x);
	fflush(stdout);
	return;
}
int query(int l,int r)
{
	if(mp.find({l,r})!=mp.end()) return mp[{l,r}];
	int x;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&x);
	mp[{l,r}]=x;
	return x;
}
void solve(int l,int r)
{
	if(l==r)
	{
		answer(l);
		return;
	}
	int mid=(l+r)/2,lmid,x=query(l,r),y;
	if(l+1==r)
	{
		if(x==l) answer(r);
		else answer(l);
		return;
	}
	int len=max(2,(int)((r-l)*0.618));
	if(x<=mid)
	{
		y=query(l,l+len-1);
		if(x==y) solve(l,l+len-1);
		else solve(l+len,r);
	}
	else
	{
		y=query(r-len+1,r);
		if(x==y) solve(r-len+1,r);
		else solve(l,r-len);
	}
	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: 100
Accepted
time: 1ms
memory: 3960kb

input:

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

output:

? 1 5
? 1 2
? 3 5
? 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: 24ms
memory: 3828kb

input:

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

output:

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

result:

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