QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613886 | #8939. Permutation | Sy03 | WA | 88ms | 3688kb | C++20 | 2.4kb | 2024-10-05 14:58:58 | 2024-10-05 15:02:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)
/**
____ ___ _____
/ ___| _ _ / _ \___ /
\___ \| | | | | | ||_ \
___) | |_| | |_| |__) |
|____/ \__, |\___/____/
|___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
for (auto &i : v)
in >> i;
return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
for (auto &i : v)
out << i << " ";
return out;
}
bool _output = 1;
int ans = -1;
bool suc = 0;
int query(int l, int r)
{
if (r - l == 0)
{
suc = 1;
ans = l;
return ans;
}
cout << "? " << l << " " << r << endl;
int x;
cin >> x;
if (r - l == 1)
{
suc = 1;
ans = r + l - x;
}
return x;
}
int make(int l, int r, int t)
{
// cout << "Debug = " << l << " " << r << " " << t << endl;
if (suc)
{
return ans;
}
if (r - l == 0)
{
suc = 1;
return l;
}
else if (r - l == 1)
{
suc = 1;
return r + l - t;
}
if (t <= (l + r) / 2)
{
int mid = (2 * r + l) / 3;
int s = query(l, mid);
if (s == t)
{
return make(l, mid, s);
}
else
{
int x = query(mid + 1, r);
return make(mid + 1, r, x);
}
}
else
{
int mid = (2 * l + r + 2) / 3;
int s = query(mid, r);
if (s == t)
{
return make(mid, r, s);
}
else
{
int x = query(l, mid - 1);
return make(l, mid - 1, x);
}
}
if (suc)
{
return ans;
}
assert(1);
}
void solve()
{
suc = 0;
ans = -1;
int n;
cin >> n;
int t = query(1, n);
int ans = make(1, n, t);
assert(ans != -1);
cout << "! " << ans << endl;
}
signed main()
{
int _ = 1;
if (_output)
cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
input:
3 5 3 2 5 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 3 ? 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: 0
Accepted
time: 63ms
memory: 3608kb
input:
10000 10 2 2 2 3 5 10 10 10 10 8 7 10 5 5 5 4 6 10 4 4 4 4 4 10 10 6 3 2 10 3 3 3 3 2 10 1 5 9 9 10 1 1 3 6 10 2 4 9 8 10 3 3 3 1 5 10 4 7 8 9 10 8 7 1 2 10 4 1 9 8 10 7 7 7 8 4 10 5 1 8 8 10 8 8 8 6 9 10 2 2 1 7 10 6 6 4 10 10 1 1 3 6 10 7 9 1 2 10 7 4 1 2 10 3 4 10 10 10 4 4 4 4 3 10 8 7 2 2 10 8 ...
output:
? 1 10 ? 1 7 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 7 ? 3 7 ? 3 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 4 10 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 7 ? 1 5 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 7 ? 8 10 ? 8 9 ! 8 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 8 10 ? 8 9 ! 10 ? ...
result:
ok Correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 88ms
memory: 3688kb
input:
10000 3 1 2 11 5 5 5 3 7 2 2 19 3 3 4 13 12 7 5 5 5 4 3 3 3 19 6 6 6 7 1 2 2 2 15 11 11 11 11 11 10 14 1 1 1 1 3 16 4 4 4 1 7 3 3 2 19 13 17 5 5 6 2 2 4 1 3 7 2 2 2 2 3 2 2 17 1 1 1 1 2 4 14 9 9 9 9 9 8 20 9 9 9 6 13 13 6 4 4 3 18 7 7 7 7 5 9 8 8 8 6 5 8 6 6 6 5 16 10 10 10 10 10 10 6 1 1 3 10 3 3 3...
output:
? 1 3 ? 1 2 ! 3 ? 1 11 ? 1 7 ? 3 7 ? 3 5 ? 6 7 ! 6 ? 1 2 ! 1 ? 1 19 ? 1 13 ? 1 9 ? 10 13 ? 11 13 ! 10 ? 1 7 ? 3 7 ? 3 5 ? 4 5 ! 3 ? 1 3 ? 2 3 ! 2 ? 1 19 ? 1 13 ? 1 9 ? 4 9 ? 1 3 ? 1 2 ! 3 ? 1 2 ! 1 ? 1 15 ? 6 15 ? 9 15 ? 9 13 ? 9 11 ? 10 11 ! 9 ? 1 14 ? 1 9 ? 1 6 ? 1 4 ? 1 3 ! 4 ? 1 16 ? 1 11 ? 1 7 ...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 86ms
memory: 3552kb
input:
10000 47 23 23 31 2 2 2 1 5 14 8 8 8 7 11 25 6 6 4 13 13 13 12 7 4 4 4 3 9 2 2 2 2 2 27 27 27 27 27 24 21 20 21 7 7 7 7 6 5 43 41 21 7 7 8 3 3 22 6 14 20 20 19 21 34 29 29 25 17 17 17 16 42 20 20 20 20 20 20 20 19 47 21 21 21 21 21 19 16 17 41 25 25 30 33 33 34 38 19 17 17 17 16 12 12 21 14 14 14 14...
output:
? 1 47 ? 1 31 ? 11 31 ? 1 10 ? 1 7 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 14 ? 6 14 ? 6 11 ? 6 9 ? 10 11 ! 10 ? 1 25 ? 1 17 ? 1 11 ? 12 17 ? 12 15 ? 12 14 ? 12 13 ! 14 ? 1 7 ? 1 5 ? 3 5 ? 3 4 ! 5 ? 1 9 ? 1 6 ? 1 4 ? 1 3 ? 1 2 ! 1 ? 1 27 ? 10 27 ? 16 27 ? 20 27 ? 23 27 ? 20 22 ? 20 21 ! 22 ? 1 21 ? 1 14 ? 1 9 ? 4...
result:
ok Correct (10000 test cases)
Test #5:
score: -100
Wrong Answer
time: 9ms
memory: 3612kb
input:
10000 100 47 61 93 96 71 71 71 71 71 9 2 2 2 2 1 53 46 35 6 6 6 6 6 6 33 3 16 31 31 31 29 32 82 60 29 4 8 23 21 26 26 88 39 39 39 25 59 59 59 59 59 59 71 24 29 59 59 59 59 60 63 92 52 52 45 88 88 88 85 91 91 24 11 11 9 5 5 5 66 51 51 51 51 45 39 39 40 92 43 43 50 20 20 20 20 20 20 19 48 1 1 1 1 1 5 ...
output:
? 1 100 ? 1 67 ? 68 100 ? 79 100 ? 68 78 ? 68 74 ? 68 72 ? 70 72 ? 70 71 ! 70 ? 1 9 ? 1 6 ? 1 4 ? 1 3 ? 1 2 ! 3 ? 1 53 ? 19 53 ? 1 18 ? 1 12 ? 1 8 ? 4 8 ? 4 6 ? 5 6 ! 5 ? 1 33 ? 1 22 ? 23 33 ? 27 33 ? 29 33 ? 29 31 ? 32 33 ! 33 ? 1 82 ? 28 82 ? 1 27 ? 1 18 ? 19 27 ? 19 24 ? 25 27 ? 25 26 ! 25 ? 1 88...
result:
wrong answer Too many queries , n = 94 , now_q 11 (test case 475)