QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#540435#8939. Permutationucup-team3510#WA 76ms3940kbC++20786b2024-08-31 17:01:112024-08-31 17:01:14

Judging History

This is the latest submission verdict.

  • [2024-08-31 17:01:14]
  • Judged
  • Verdict: WA
  • Time: 76ms
  • Memory: 3940kb
  • [2024-08-31 17:01:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int t,n;
int query(int l,int r)
{
	if(l==r)return -1;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	int x;scanf("%d",&x);
	return x;
}
int solve(int l,int r,int p)
{//printf("solve([%d,%d],%d)\n",l,r,p);
	if(l==r)return l;
	if(p==-1)p=query(l,r);
	if(r-l+1==2)return l^r^p;
	int m;
	int len=(r-l+1+1)/2;
	if(p<=l+len-1)m=l+len-1;
	else m=r-len;
	if(p<=m)
	{
		int tt=query(l,m);
		if(tt==p)return solve(l,m,tt);
		else return solve(m+1,r,-1);
	}
	else
	{
		int tt=query(m+1,r);
		if(tt==p)return solve(m+1,r,tt);
		else return solve(l,m,-1);
	}
}
int main()
{
	scanf("%d",&t);while(t--)
	{
		scanf("%d",&n);
		printf("! %d\n",solve(1,n,-1));fflush(stdout);
	}
	fclose(stdin);fclose(stdout);return 0;
}

详细

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 76ms
memory: 3864kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 31ms
memory: 3940kb

input:

10000
3
1
2
11
5
5
5
4
2
2
19
3
3
4
6
8
9
7
5
7
1
2
3
3
3
19
6
6
10
1
1
2
2
2
15
11
11
11
10
8
14
1
1
1
2
3
16
4
4
1
8
7
5
3
3
2
19
13
17
5
5
5
4
2
2
4
1
2
3
7
2
2
2
3
2
2
17
1
1
1
2
4
14
9
9
9
8
11
20
9
3
18
17
13
13
13
6
4
4
5
18
7
7
7
5
9
8
8
6
3
3
8
6
7
1
2
3
16
10
10
10
10
6
1
3
6
5
10
3
3
1
4
...

output:

? 1 3
? 1 2
! 3
? 1 11
? 1 6
? 4 6
? 4 5
! 6
? 1 2
! 1
? 1 19
? 1 10
? 1 5
? 6 10
? 6 8
? 9 10
! 10
? 1 7
? 4 7
? 1 3
? 1 2
! 3
? 1 3
? 2 3
! 2
? 1 19
? 1 10
? 6 10
? 1 5
? 1 3
? 1 2
! 3
? 1 2
! 1
? 1 15
? 8 15
? 8 11
? 10 11
? 8 9
! 9
? 1 14
? 1 7
? 1 4
? 1 2
? 3 4
! 4
? 1 16
? 1 8
? 1 4
? 5 8
? 7 ...

result:

wrong answer Too many queries , n = 16 , now_q 7 (test case 34)