QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858083#8939. PermutationluuiaWA 1ms3584kbC++14758b2025-01-16 13:56:242025-01-16 13:57:10

Judging History

This is the latest submission verdict.

  • [2025-01-16 13:57:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3584kb
  • [2025-01-16 13:56:24]
  • Submitted

answer

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

const int N = 1e6 + 10;
const double t = 0.618;
ll T,n,m,o,s,l,r,L,R;

ll query(ll l,ll r)
{
	ll o;cout << "? " << l << " " << r << '\n';
	cin >> o;return o;
}

void cal(ll l,ll r,ll x)
{
	if(l == r){cout << "! " << l << '\n';return;}
	ll o1 = l - 1 + (r - l + 1) * t,o2 = ceil(r - (r - l + 1) * t + 1);
	if(o1 < x && o2 > x) o1++;
	if(x <= o1)
	{
		if(query(l,o1) == x) cal(l,o1,x);
		else cal(o1 + 1,r,query(o1 + 1,r));
	}
	else
	{
		if(query(o2,r) == x) cal(o2,r,x);
		else cal(l,o2 - 1,query(l,o2 - 1));
	}
}


void sol(){cin >> n,s = query(1,n),cal(1,n,s);}

int main()
{
	// freopen("input.in","r",stdin);
	cin >> T;while(T--) sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
2
5

output:

? 1 5
? 1 3
? 4 5
? 5 5

result:

wrong answer Integer 5 violates the range [1, 4] (test case 1)