QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424005 | #962. Thanks to MikeMirzayanov | Hunster | WA | 0ms | 3792kb | C++14 | 2.8kb | 2024-05-28 20:43:57 | 2024-05-28 20:43:58 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int N = 2000;
int n, c[N], _c[N];
std::vector<std::tuple<int, int, int>> ans[125];
std::mt19937 rng((std::random_device())());
// std::mt19937 rng(0);
int maxd;
void work(int l, int r, int d) {
if (l >= r) return;
int v = c[std::uniform_int_distribution<int>(l, r)(rng)];
std::vector<std::pair<int, int>> e;
int w = 0;
for (int i = l; i <= r; i++) {
w += c[i] <= v;
e.push_back({c[i] > v, c[i]});
}
while (true) {
int cur = 0;
std::vector<int> t;
for (int i = 0, j; i < e.size(); i = j) {
for (j = i; j < e.size() && e[j].first == cur; j++) ;
t.push_back(j);
cur ^= 1;
}
if (t.size() < 3) break;
d++;
std::vector<std::pair<int, int>> _e;
const auto insert = [&](int i) {
int l = i ? t[i - 1] : 0, r = t[i];
for (int p = l; p < r; p++) _e.push_back(e[p]);
};
for (int i = 0; i < t.size(); i += 4) {
insert(i);
if (i + 2 < t.size()) insert(i + 2);
if (i + 1 < t.size()) insert(i + 1);
if (i + 3 < t.size()) insert(i + 3);
if (i + 2 < t.size()) ans[d].push_back({l + t[i], l + t[i + 1], l + t[i + 2]});
}
std::swap(e, _e);
}
maxd = std::max(maxd, d);
for (int i = l; i <= r; i++) c[i] = e[i - l].second;
work(l, l + w - 1, d);
work(l + w, r, d);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
work(1, n, 0);
for (int i = 1; i <= n; i++) assert(c[i] == i);
std::vector<std::vector<int>> all;
for (int i = 1; i <= maxd; i++) {
std::vector<int> w1, w2;
{
auto [x, y, z] = ans[i].front();
if (x > 1) {
w1.push_back(x - 1);
w2.push_back(x - 1);
}
}
for (int j = 0; j < ans[i].size(); j++) {
auto [x, y, z] = ans[i][j];
w1.push_back(z - x);
w2.push_back(z - y);
w2.push_back(y - x);
if (j > 0) {
auto [_x, _y, _z] = ans[i][j - 1];
if (_z < x) {
w1.push_back(x - _z);
w2.push_back(x - _z);
}
}
}
{
auto [x, y, z] = ans[i].back();
if (z <= n) {
w1.push_back(n - z + 1);
w2.push_back(n - z + 1);
}
}
if (w1.size() > 1) all.push_back(w1);
if (w2.size() > 1) all.push_back(w2);
}
printf("%lu\n", all.size());
for (auto w : all) {
printf("%lu ", w.size());
for (int x : w) printf("%d ", x);
puts("");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3792kb
input:
4 3 1 2 4
output:
2 2 3 1 3 2 1 1
result:
wrong answer the permutation is not sorted