QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557360#8939. PermutationsynonymTL 0ms0kbC++17919b2024-09-11 09:14:562024-09-11 09:14:57

Judging History

This is the latest submission verdict.

  • [2024-09-11 09:14:57]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-11 09:14:56]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define fnt long double
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

int get_second(int l, int r) {
	cout<<"? "<<l<<" "<<r<<endl;
	int res; cin>>res;
	return res;
}

const fnt V = .618;

void solve() {
	int n; cin>>n;
	int l=1,r=n;
	while (l != r) {
		int p = get_second(l,r);
		if (l+1==r) {
			cout<<l+r-p<<endl;
			return;
		}
		int lrp = l+V*(r-l+1);
		int rrp = r-V*(r-l+1);
		int p2 = -1;
		if (p <= lrp) {
			p2 = get_second(l,lrp);
			if (p2 == p) {
				r = lrp;
			} else {
				l = lrp+1;
			}
		} else {
			assert(p >= rrp);
			p2 = get_second(rrp,r);
			if (p2 == p) {
				l = rrp;
			} else {
				r = rrp-1;
			}
		}
	}
	cout<<l<<endl;
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int t; cin>>t;
	while (t--) {
		solve();
	}
	
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3
3
3

output:

? 1 5
? 1 4
? 1 4
? 1 3

result: