QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424008#962. Thanks to MikeMirzayanovHunsterWA 0ms4076kbC++142.9kb2024-05-28 20:44:522024-05-28 20:44:52

Judging History

你现在查看的是最新测评结果

  • [2024-05-28 20:44:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4076kb
  • [2024-05-28 20:44:52]
  • 提交

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);
            }
        }
        std::reverse(w2.begin(), w2.end());
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

4
3 1 2 4

output:

2
2 3 1 
3 1 1 2 

result:

ok OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

6
6 5 4 3 2 1

output:

5
2 3 3 
2 3 3 
4 1 2 2 1 
4 1 2 2 1 
6 1 1 1 1 1 1 

result:

ok OK

Test #3:

score: 0
Accepted
time: 0ms
memory: 4076kb

input:

1
1

output:

0

result:

ok OK

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

input:

10
3 8 7 4 6 2 9 10 1 5

output:

16
2 7 3 
3 1 2 7 
2 6 4 
3 4 5 1 
3 1 7 2 
4 2 6 1 1 
4 2 2 5 1 
6 1 5 1 1 1 1 
3 3 3 4 
4 4 2 1 3 
3 4 4 2 
4 2 3 1 4 
3 5 3 2 
4 2 2 1 5 
3 6 2 2 
4 2 1 1 6 

result:

wrong answer the permutation is not sorted