QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614847#8939. PermutationHencechoWA 9ms3696kbC++141.7kb2024-10-05 17:01:322024-10-05 17:01:34

Judging History

This is the latest submission verdict.

  • [2024-10-05 17:01:34]
  • Judged
  • Verdict: WA
  • Time: 9ms
  • Memory: 3696kb
  • [2024-10-05 17:01:32]
  • 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.570;
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-1 + max(1.0L,(r - l + 1) * 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+1 - max(1.0L,(r - l + 1) * 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: 3696kb

input:

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

output:

? 1 5
? 3 5
? 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: 9ms
memory: 3612kb

input:

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

output:

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

result:

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