QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607208#8939. PermutationUESTC_NLNS#WA 51ms4080kbC++14915b2024-10-03 14:17:322024-10-03 14:17:33

Judging History

This is the latest submission verdict.

  • [2024-10-03 14:17:33]
  • Judged
  • Verdict: WA
  • Time: 51ms
  • Memory: 4080kb
  • [2024-10-03 14:17:32]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
unordered_map<ll,int> mp;
const int N=1e6+5;
void answer(int x)
{
	printf("! %d\n",x);
	fflush(stdout);
	return;
}
int query(int l,int r)
{
	ll id=1ll*l*N+r;
	if(mp.find(id)!=mp.end()) return mp[id];
	int x;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&x);
	mp[id]=x;
	return x;
}
void solve(int l,int r)
{
	if(l==r)
	{
		answer(l);
		return;
	}
	int mid=(l+r)>>1,x=query(l,r),y;
	if(l+1==r)
	{
		if(x==l) answer(r);
		else answer(l);
		return;
	}
	if(x<=mid)
	{
		y=query(l,mid);
		if(x==y) solve(l,mid);
		else solve(mid+1,r);
	}
	else
	{
		if(mid+1==r) {solve(l,r-1);return;}
		y=query(mid+1,r);
		if(x==y) solve(mid+1,r);
		else solve(l,mid);
	}
	return;
}
int T,n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		solve(1,n);
		mp.clear();
	}
	return 0;
}

详细

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 51ms
memory: 4080kb

input:

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

output:

? 1 10
? 1 5
? 1 3
? 4 5
! 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)