QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614862#8939. PermutationHencechoWA 7ms3700kbC++141.7kb2024-10-05 17:03:212024-10-05 17:03:22

Judging History

This is the latest submission verdict.

  • [2024-10-05 17:03:22]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3700kb
  • [2024-10-05 17:03:21]
  • Submitted

answer

#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a), __ENDi__ = (b); i <= __ENDi__; i++)
#define fd(i, a, b) for (int i = (a), __ENDi__ = (b); i >= __ENDi__; i--)
typedef long long ll;
using namespace std;
const long double alpha = 0.6182;
int l,r,pos;
map <int,map<int,int> > que;
int ask(int l,int r)
{
	if (que[l][r]) return que[l][r];
	cout << "? " << l << ' ' << r << endl;
	cout.flush();
	int res;
	cin >> res;
	que[l][r] = res;
	return res;
}
void check(int l,int r)
{
	if (pos) return ; 
	pos = ask(l,r);
	return ;
}
signed main()
{
	int T;
	cin >> T;
//	cout << alpha << ' ';
//	return 0;
	while(T--)
	{
		que.clear();
		cin >> r;
		l = 1;pos = 0;
		while(l < r)
		{
			check(l,r);
			que[l][r] = pos;
			if (r - l + 1 == 2)
			{
				int res = l ^ r ^ ask(l,r);
				l = r = res;
				continue;
			}
			if (r - l + 1 == 3)
			{
				int res = ask(l,r);
				if (l == res) 
				{
					l++;
					pos = 0;
					continue;
				}
				if (r == res) 
				{
					r--;
					pos = 0;
					continue;
				}
				int res2 = ask(l,l+1);
				if (res2 == l + 1) r = l;else l = r;
				continue;
			}
			if (pos - l < r - pos)
			{
				int R = max(pos,(int)(l + max(1.0L,(r - l) * alpha)));
				int res = ask(l,R);
				if (res == pos) 
				{
					r = R;
					continue;
				}else 
				{
					l = min(R + 1,r);
					pos = 0;
					continue;
				}
			}//左边更加短。
			else
			{
				int L = min(pos,(int)(r - max(1.0L,(r - l) * alpha)));
				int res = ask(L,r);
				if (res == pos)
				{
					l = L;
					continue;
				}else
				{
					r = max(l,L - 1);
					pos = 0;
					continue;
				}
			}
		}
		cout << "! " << l << endl;
		cout.flush();
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 3700kb

input:

10000
10
2
2
2
1
3
10
10
10
10
7
10
5
1
10
9
10
4
4
4
4
4
10
10
6
3
2
10
3
3
3
2
10
1
5
9
9
9
10
1
3
8
8
10
2
4
9
9
8
10
3
3
3
3
2
10
4
1
7
8
9
10
8
7
1
2
10
4
1
9
9
8
10
7
7
8
4
10
5
1
7
8
10
10
8
8
8
8
7

output:

? 1 10
? 1 6
? 1 4
? 1 2
? 3 4
! 4
? 1 10
? 4 10
? 6 10
? 7 10
! 6
? 1 10
? 1 6
? 7 10
? 8 10
! 7
? 1 10
? 1 6
? 2 6
? 3 6
? 3 4
! 3
? 1 10
? 4 10
? 1 3
? 1 2
! 1
? 1 10
? 1 6
? 1 4
? 2 4
! 1
? 1 10
? 1 6
? 7 10
? 8 10
? 8 9
! 8
? 1 10
? 1 6
? 7 10
? 7 8
! 7
? 1 10
? 1 6
? 7 10
? 8 10
? 8 9
! 10
? 1...

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 16)