QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424073 | #962. Thanks to MikeMirzayanov | Hunster | WA | 1ms | 4096kb | C++14 | 2.5kb | 2024-05-28 21:28:30 | 2024-05-28 21:28:32 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int N = 20004;
int n, c[N];
std::vector<std::pair<int, int>> ans[125];
int maxd;
void work(int l, int r, int d) {
if (l >= r) return;
std::vector<int> vec;
for (int i = l; i <= r; i++) vec.push_back(c[i]);
std::sort(vec.begin(), vec.end());
int w = vec.size() >> 1, v = vec[w - 1];
std::vector<std::pair<int, int>> e;
for (int i = l; i <= r; i++) 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++;
for (int i = 0; i + 2 < t.size(); i += 4) {
ans[d].push_back({l + t[i], l + t[i + 2]});
std::reverse(e.begin() + t[i], e.begin() + t[i + 2]);
}
}
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;
int cur = 0;
for (int i = 1; i <= maxd; i++) {
// std::cerr << i << ":\n";
// for (auto [x, y] : ans[i]) std::cerr << x << " " << y << "\n";
// std::cerr << std::endl;
std::vector<int> w;
{
auto [x, y] = ans[i].front();
for (int o = 1; o < x; o++) w.push_back(1);
}
for (int j = 0; j < ans[i].size(); j++) {
auto [x, y] = ans[i][j];
if (j > 0) {
auto [_x, _y] = ans[i][j - 1];
for (int o = _y; o < x; o++) w.push_back(1);
}
w.push_back(y - x);
}
{
auto [x, y] = ans[i].back();
for (int o = y; o <= n; o++) w.push_back(1);
}
if (w.size() > 1) {
if (cur) std::reverse(w.begin(), w.end());
all.push_back(w);
}
cur ^= 1;
}
if (cur) {
all.emplace_back(n);
std::iota(all.back().begin(), all.back().end(), 1);
}
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: 100
Accepted
time: 1ms
memory: 4088kb
input:
4 3 1 2 4
output:
2 2 3 1 3 1 1 2
result:
ok OK
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4096kb
input:
6 6 5 4 3 2 1
output:
1 6 1 2 3 4 5 6
result:
wrong answer total size of all parts is not equal to size of premutation