QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#614887#8939. PermutationHencechoTL 0ms0kbC++141.7kb2024-10-05 17:06:122024-10-05 17:06:13

Judging History

This is the latest submission verdict.

  • [2024-10-05 17:06:13]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-05 17:06:12]
  • 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 + 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- 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;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
3

output:

? 1 5

result: