QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555538#8939. PermutationInsert_Username_HereWA 1ms3648kbC++201.1kb2024-09-10 03:35:102024-09-10 03:35:10

Judging History

This is the latest submission verdict.

  • [2024-09-10 03:35:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3648kb
  • [2024-09-10 03:35:10]
  • Submitted

answer

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// const ll mod = 1e9 + 7;
// #include <brawlstars>
// FOR PAIN OR FOR GLORYYY ELLL PRIMOOOOOO

const double rt = 0.61803398875;
int qry(int l, int r) {
	int ans;
	cout << "? " << l << " " << r << "\n";
	cout.flush();
	cin >> ans;
	return ans;
}
int f(int l, int r) {
	int mid, pos = qry(l, r);
	while(r - l > 2) {
		mid = l + (r - l + 1) * rt - 1;
		if(pos <= mid) {
			(qry(l, mid) == pos) ? r = mid : l = mid + 1;
			if(l > mid) pos = qry(l, r);
		} else {
			mid = r - (r - l + 1) * rt + 1;
			(qry(mid, r) == pos) ? l = mid : r = mid - 1;
			if(r < mid) pos = qry(l, r);
		}
	}
	if(r - l == 1) return (l == pos ? r : l);
	if(l == pos) return (r == qry(r - 1, r) ? r - 1 : r);
	if(r == pos) return (l == qry(l, l + 1) ? l + 1 : l);
	return (l + 1 == qry(l, l + 1) ? l : r);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int ans = f(1, n);
		cout << "! " << ans << "\n";
		cout.flush();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

input:

3
5
3
2
5
6
6
3
1
4
3
3
2

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3648kb

input:

10000
10
2
2
3
5
5
10
10
10
10
7

output:

? 1 10
? 1 6
? 1 3
? 4 6
? 4 5
! 4
? 1 10
? 4 10
? 6 10
? 7 10
? 6 6

result:

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