QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858124#8939. PermutationoXUoTL 0ms3584kbC++14998b2025-01-16 14:19:232025-01-16 14:19:25

Judging History

This is the latest submission verdict.

  • [2025-01-16 14:19:25]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3584kb
  • [2025-01-16 14:19:23]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2e5+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}


int n;
int ask(int l,int r){
	if(l == r)return 0;
	printf("? %d %d\n",l,r);
	cout.flush();
	int x = read();
	return x;
}
void solve(){
	n = read();
	int p = ask(1,n);
	int l = 1,r = n;
	while(l < r){
		int mid = (l + r) >> 1;
		if(p <= mid){
			int x = ask(l,mid);
			if(x == p)r = mid;
			else l = mid + 1,p = ask(mid + 1,r);
		}
		else{
			int x = ask(mid + 1,r);
			if(x == p)l = mid + 1;
			else r = mid,p = ask(l,mid);
		}
	}
	printf("! %d\n",l);
	cout.flush();
}

int main(){
	int t = read();
	while(t--)solve();

	return 0;

}



详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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
Time Limit Exceeded

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: