QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614896 | #8939. Permutation | Hencecho | TL | 0ms | 0kb | C++14 | 1.7kb | 2024-10-05 17:07:21 | 2024-10-05 17:07:22 |
Judging History
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 - 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- 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