QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858274#8939. PermutationlittleandyTL 0ms0kbC++14775b2025-01-16 15:32:152025-01-16 15:32:17

Judging History

This is the latest submission verdict.

  • [2025-01-16 15:32:17]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-16 15:32:15]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const double P = (sqrt(5) - 1.0) / 2.0;
int ask(int l, int r) {
	if (l == r) return 0;
	printf("? %d %d\n", l, r);
	int res; scanf("%d", &res);
	return res;
}
void work() {
	int n, l = 1;
	scanf("%d", &n);
	int res = ask(1, n), r = n;
	while (l < r) {
		int mid1 = floor(double(l * (1.0 - P) + r * P));
		int mid2 = floor(double(l * P + r * (1.0 - P)));
		if (res <= mid2) {
			int Res = ask(l, mid1);
			if (res == Res) r = mid1;
			else res = ask(mid1 + 1, r), l = mid1 + 1;
		} else {
			int Res = ask(mid2 + 1, r);
			if (res == Res) l = mid2 + 1;
			else res = ask(l, mid2), r = mid2;
		}
	}
	printf("! %d\n", l);
}
int main() {
	int t, n;
	scanf("%d", &t);
	while (t--) work();
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5

output:


result: