QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858292#8939. PermutationlittleandyTL 0ms0kbC++14738b2025-01-16 15:42:112025-01-16 15:42:20

Judging History

This is the latest submission verdict.

  • [2025-01-16 15:42:20]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-16 15:42:11]
  • 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 tmpl = l, tmpr = r;
		int mid1 = l + r >> 1;
		int mid2 = l + r >> 1;
		if (res <= mid2)
			if (res == ask(l, mid1)) r = mid1;
			else res = ask(mid1 + 1, r), l = mid1 + 1;
		else
			if (res == ask(mid2 + 1, r)) l = mid2 + 1;
			else res = ask(l, mid2), r = mid2;
		if (tmpl == l && tmpr == r) exit(1);
	}
	printf("! %d\n", l);
}
int main() {
	int t;
	scanf("%d", &t);
	while (t--) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
5

output:


result: