QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610486 | #8939. Permutation | ucup-team4975# | RE | 73ms | 19404kb | C++23 | 2.8kb | 2024-10-04 16:09:51 | 2024-10-04 16:09:51 |
Judging History
answer
// #define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
using namespace std;
using PII = pair<int, int>;
const int N = 1000010;
mt19937_64 rng{chrono::steady_clock::now().time_since_epoch().count()};
int n, p[N], cnt = 0, ress = 0;
int fib[N], f[N], las[N], fir[N];
void input()
{
cin >> n;
// n = rand() % 16 + 1;
// cout << ceil(1.5 * log(n) / log(2)) << endl;
#ifdef LOCAL
vector<int> vis(n + 1, 0);
for (int i = 1; i <= n; i++) {
int res = rng() % n + 1;
while (vis[res])
res = rng() % n + 1;
vis[res] = 1;
p[i] = res;
}
/*cout << n << endl;
for (int i = 1; i <= n; i++) {
cout << p[i] << " ";
}
cout << endl;*/
#endif
}
int query(int l, int r)
{
cnt++;
ress += (r - l + 1);
assert(cnt <= ceil(1.5 * log(n) / log(2)));
assert(ress <= n * 3);
#ifdef LOCAL
map<int, int> mp;
for (int i = l; i <= r; i++) {
mp.insert(PII(p[i], i));
}
auto res = mp.end();
res--;
res--;
return res->sec;
#else
int inp;
cout << "? " << l << " " << r << endl;
cin >> inp;
return inp;
#endif
}
int getans(int l, int r, int flag)
// flag == 0 表示 需要询问l-r的答案,否则答案为flag
{
if (l == r) {
return l;
}
if (!flag) {
flag = query(l, r);
}
// cout << l << " " << r << " " << flag << endl;
if (r == l + 1) {
return l + r - flag;
}
int len = r - l + 1;
// cout << len << " " << las[len] << endl;
if (l + las[len] - 1 >= flag) {
// flag在左半区间
int now = query(l, l + las[len] - 1);
if (now == flag) {
return getans(l, l + las[len] - 1, now);
}
else {
return getans(l + las[len], r, 0);
}
}
else if (r - las[len] + 1 <= flag) {
int now = query(r - las[len] + 1, r);
if (now == flag) {
return getans(r - las[len] + 1, r, now);
}
else {
return getans(l, r - las[len], 0);
}
}
}
void solve()
{
cnt = 0, ress = 0;
input();
int ans = getans(1, n, 0);
#ifdef LOCAL
// cout << "right ans :: ";
for (int i = 1; i <= n; i++) {
if (p[i] == n) {
cout << "right ans :: " << i << endl;
}
}
#endif
cout << "! " << ans << endl;
}
int main()
{
int maxn = 1000000, tot = 0;
f[1] = 0, f[2] = 1;
fib[1] = 1, fib[2] = 2;
las[2] = 1;
for (tot = 3;; tot++) {
fib[tot] = fib[tot - 1] + fib[tot - 2];
if (fib[tot] > maxn)
break;
}
for (int i = 3; i <= maxn; i++) {
las[i] = 0;
int fl = 0;
for (int j = tot; j >= 1; j--) {
if (fib[j] < i) {
fir[i] = i - fib[j - 1];
las[i] = fib[j];
break;
}
}
f[i] = 1 + max(f[las[i]], 1 + f[i - las[i]]);
// cout << i << " " << las[i] << endl;
if (fir[i] <= (i + 1) / 2 && (i + 1) / 2 <= las[i]) {
las[i] = (i + 1) / 2;
}
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 17116kb
input:
3 5 3 2 5 6 6 5 3 3 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 68ms
memory: 17160kb
input:
10000 10 2 2 3 5 10 10 10 8 7 10 5 1 10 9 6 10 4 4 4 4 10 10 6 3 3 2 10 3 3 3 2 10 1 5 9 9 9 10 1 3 8 8 8 10 2 4 9 9 8 10 3 3 1 5 10 4 1 7 8 9 10 8 7 1 1 2 10 4 1 9 9 8 10 7 8 2 1 4 10 5 1 7 6 10 10 8 8 6 9 10 2 1 7 7 7 10 6 6 8 10 10 1 3 8 8 8 10 7 9 5 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 ? 6 8 ? 7...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 73ms
memory: 19140kb
input:
10000 47 23 23 31 11 9 2 1 5 14 8 8 8 9 11 25 6 13 21 21 18 15 15 7 4 2 6 6 9 2 2 2 2 27 27 27 27 24 21 21 21 7 7 7 7 6 5 43 41 37 7 7 7 8 3 3 22 6 4 14 12 20 19 21 34 29 29 25 17 17 18 14 42 20 20 20 20 20 19 17 47 21 21 21 21 21 21 19 17 41 25 25 30 34 34 36 38 19 17 17 16 7 9 10 21 14 14 14 14 14...
output:
? 1 47 ? 1 34 ? 14 34 ? 1 13 ? 6 13 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 14 ? 8 14 ? 8 11 ? 8 9 ? 10 11 ! 10 ? 1 25 ? 1 13 ? 14 25 ? 14 21 ? 17 21 ? 14 16 ? 14 15 ! 14 ? 1 7 ? 1 4 ? 5 7 ? 5 6 ! 5 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 1 ? 1 27 ? 14 27 ? 21 27 ? 24 27 ? 21 23 ? 21 22 ! 22 ? 1 21 ? 1 13 ? 1 8 ? 4 8 ? 6 8 ? 4...
result:
ok Correct (10000 test cases)
Test #5:
score: -100
Runtime Error
input:
10000 100 47 5 61 61 61 53 71 71 71 71 9 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 23 21 26 26 88 39 8 59 59 59 59 59 59 59 71 24 29 59 59 60 61 61 92 52 52 70 88 81 89 89 24 11 11 9 3 3 66 51 51 51 45 39 39 38 40 92 43 43 43 38 20 20 20 20 19 48 1 1 1 1 1 5 7 6 85 28 28 28...
output:
? 1 100 ? 1 50 ? 51 100 ? 51 84 ? 51 71 ? 51 63 ? 64 71 ? 67 71 ? 69 71 ? 70 71 ! 70 ? 1 9 ? 1 5 ? 1 3 ? 1 2 ! 3 ? 1 53 ? 20 53 ? 1 19 ? 1 13 ? 1 8 ? 4 8 ? 4 6 ? 5 6 ! 5 ? 1 33 ? 1 21 ? 22 33 ? 26 33 ? 29 33 ? 29 31 ? 32 33 ! 33 ? 1 82 ? 28 82 ? 1 27 ? 1 14 ? 15 27 ? 20 27 ? 20 24 ? 25 27 ? 25 26 ! ...