QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559159 | #8939. Permutation | Yarema | RE | 1ms | 3780kb | C++20 | 1.5kb | 2024-09-11 20:35:22 | 2024-09-11 20:35:22 |
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;
}
int n = (r - l);
int x = ask(l, r - 1);
int m = (l + r) / 2;
if(x < m)
{
int m2 = l + n * 0.64;
if(ask(l, m2 - 1) == x)
return solve(l, m2);
return solve(m2, r);
}
else
{
int m2 = r - n * 0.64;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
input:
3 5 3 3 2 5 6 6 3 1 4 3 3 3
output:
? 1 5 ? 2 5 ? 2 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Runtime Error
input:
10000 10 2 2 3 5 6 10 10 10 10 7 10 5 1 10 9 10 4 4 4 4 10 10 6 3 2 10 3 3 3 2 10 1 5 9 9 10 10 1 3 8 8 10 2 4 9 9 9 10 3 3 1 5 6 10 4 1 7 8 9 10 8 7 1 2 10 4 1 9 9 9 10 7 7 8 4 10 5 1 7 8 10 10 8 8 8 8 7
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 5 6 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ! 7 ? 1 10 ? 1 6 ? 3 6 ? 3 4 ! 3 ? 1 10 ? 4 10 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 6 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ? 9 10 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ? 9 10 ! 10 ? 1 10 ...