QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#542884#8939. Permutationucup-team1766#RE 0ms0kbC++23956b2024-09-01 06:54:132024-09-01 06:54:15

Judging History

This is the latest submission verdict.

  • [2024-09-01 06:54:15]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-01 06:54:13]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const long double d = 1/2.62L;
int n;

int sum = 0;
void query(int l, int r) {
	assert(1 <= l and l <= r);
	sum += r - l + 1;
	assert(sum <= 3*n);
	cout << "? " << l << " " << r << endl;
}

void run() {
	cin >> n;

	int l = 1, r = n;
	int mx = -1;
	while (l+1 < r) {
		if (mx == -1) {
			query(l, r);
			cin >> mx;
		}
		if (mx <= l + (r - l) / 2) {
			int m = r - int((r - l + 1) * d);
			if (m == r) m--;
			query(l, m);
			int x; cin >> x;
			if (x == mx) {
				r = m;
			} else {
				l = m+1;
				mx = -1;
			}
		} else {
			int m = l + int((r - l + 1) * d);
			if (m == l) m++;
			query(m, r);
			int x; cin >> x;
			if (x == mx) {
				l = m;
			} else {
				r = m-1;
				mx = -1;
			}
		}
	}
	if (l+1 == r) {
		if (mx == -1) {
			query(l, r);
			cin >> mx;
		}
		if (mx == l) l = r;
	}

	cout << "! " << l << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t; cin >> t; while (t--) run();
}

详细

Test #1:

score: 0
Runtime Error

input:

3
5
3
3
3
2
6

output:

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

result: