QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558939 | #8939. Permutation | Yarema# | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-09-11 19:24:01 | 2024-09-11 19:24:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;
int N;
int sum = 0;
int QUERY;
map<PII, int> res;
int ask(int l, int r)
{
if (l >= r)
return -1;
if(res.count(MP(l, r)))
return res[MP(l, r)];
sum += (r - l + 1);
assert(sum <= 3 * N);
assert(SZ(res) + 1 <= QUERY);
cout << "? " << l + 1 << ' ' << r + 1 << endl;
int x;
cin >> x;
return res[MP(l, r)] = x - 1;
}
int solve(int l, int r)
{
if (l + 1 == r)
return l + 1;
if (l + 2 == r)
{
int x = ask(l, l + 1);
return 2 * l + 1 - x + 1;
}
if(l + 3 == r)
{
int x = ask(l, l + 2);
if(x == l + 1)
{
if(ask(l, x) == x)
return l + 1;
return solve(l + 1, r);
}
if(x == l)
return solve(l + 1, r);
return solve(l, r - 1);
}
int x = ask(l, r - 1);
int m = (l + r) / 2;
if(x < m)
{
int m2 = (l + 3 * r) / 5;
if(ask(l, m2 - 1) == x)
return solve(l, m2);
return solve(m2, r);
}
else
{
int m2 = (3 * l + r) / 5;
if(ask(m2, r - 1) == x)
return solve(m2, r);
return solve(l, m2);
}
}
void solve()
{
int n;
cin >> n;
N = n;
sum = 0;
QUERY = ceil(1.5 * log(n) / log(2));
res.clear();
int ans = solve(0, n);
cout << "! " << ans << endl;
}
int main()
{
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 5 3 3 2 5 6 6 6
output:
? 1 5 ? 2 5 ? 2 3 ? 4 5 ! 4 ? 1 6 ? 2 6