QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858181#8939. PermutationoXUoTL 0ms0kbC++141.0kb2025-01-16 14:45:472025-01-16 14:45:53

Judging History

This is the latest submission verdict.

  • [2025-01-16 14:45:53]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-16 14:45:47]
  • 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 + ((double)r - l) * (1 - 0.618);
		if(p <= mid){
			int x = ask(l,mid);
			if(x == p)r = mid;
			else l = mid + 1,p = ask(mid + 1,r);
		}
		else{
			mid = r - ((double)r - l) * (1 - 0.618);
			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;

}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3
5
2
1

output:

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

result: