QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684440#8939. Permutationreal_sigma_team#WA 1ms3564kbC++23965b2024-10-28 13:31:122024-10-28 13:31:13

Judging History

This is the latest submission verdict.

  • [2024-10-28 13:31:13]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3564kb
  • [2024-10-28 13:31:12]
  • Submitted

answer

#include<bits/stdc++.h>

int main() {
	// std::cin.tie(nullptr)->sync_with_stdio(false);

	int tests;
	std::cin >> tests;
	while (tests--) {
		int n;
		std::cin >> n;
		auto rec = [&](auto rec, int l, int r, int p) -> void {
			if (l == r || (r - l == 1 && p != -1)) {
				if (l == p) std::cout << "! " << r << std::endl;
				else std::cout << "! " << l << std::endl;
				return;
			}
			if (p == -1) {
				std::cout << "? " << l << ' ' << r << std::endl;
				std::cin >> p;
			}
			int m1 = (2 * l + r) / 3;
			int m2 = (l + r * 2) / 3;
			if (p > m1) {
				std::cout << "? " << m1 + 1 << ' ' << r << std::endl;
				int shq;
				std::cin >> shq;
				if (shq == p) rec(rec, m1 + 1, r, p);
				else rec(rec, l, m1, -1);
			} else {
				std::cout << "? " << l << ' ' << m2 << std::endl;
				int shq;
				std::cin >> shq;
				if (shq == p) rec(rec, l, m2, p);
				else rec(rec, m2 + 1, r, -1);
			}
		};
		rec(rec, 1, n, -1);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3564kb

input:

3
5
3
3
3
6
6
3
1

output:

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

result:

wrong answer Integer 1 violates the range [2, 6] (test case 2)