QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424019#962. Thanks to MikeMirzayanovHunsterWA 2ms4228kbC++143.0kb2024-05-28 20:51:582024-05-28 20:51:59

Judging History

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

  • [2024-05-28 20:51:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4228kb
  • [2024-05-28 20:51:58]
  • 提交

answer

#include <bits/stdc++.h>

constexpr int N = 2003;

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::cerr << i << ":\n";
        // for (auto [x, y, z] : ans[i]) std::cerr << x << " " << y << " " << z << "\n";
        // std::cerr << std::endl;
        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];
            if (j > 0) {
                auto [_x, _y, _z] = ans[i][j - 1];
                if (_z < x) {
                    w1.push_back(x - _z);
                    w2.push_back(x - _z);
                }
            }
            w1.push_back(z - x);
            w2.push_back(z - y);
            w2.push_back(y - x);
        }
        {
            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: 1ms
memory: 3920kb

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: 3912kb

input:

6
6 5 4 3 2 1

output:

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

result:

ok OK

Test #3:

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

input:

1
1

output:

0

result:

ok OK

Test #4:

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

input:

10
3 8 7 4 6 2 9 10 1 5

output:

12
2 6 4 
3 4 5 1 
3 1 8 1 
4 1 7 1 1 
3 2 6 2 
5 1 1 6 1 1 
3 3 4 3 
4 3 2 2 3 
3 5 4 1 
4 1 3 1 5 
4 4 2 2 2 
6 2 1 1 1 1 4 

result:

ok OK

Test #5:

score: 0
Accepted
time: 1ms
memory: 4132kb

input:

20
2 13 11 1 19 12 15 3 9 4 14 18 17 7 16 8 6 10 5 20

output:

20
5 4 2 5 3 6 
7 6 2 1 5 1 1 4 
3 5 7 8 
4 8 2 5 5 
3 10 9 1 
4 1 5 4 10 
8 1 3 2 2 4 2 2 4 
12 4 1 1 1 1 4 1 1 2 2 1 1 
5 2 5 8 4 1 
7 1 2 2 8 3 2 2 
6 4 9 2 2 2 1 
9 1 1 1 1 1 2 5 4 4 
4 4 4 4 8 
6 8 3 1 2 2 4 
6 2 2 2 3 5 6 
9 6 4 1 3 1 1 2 1 1 
3 10 2 8 
4 8 1 1 10 
3 11 2 7 
4 7 1 1 11 

result:

ok OK

Test #6:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

50
42 29 21 50 27 23 7 43 46 13 37 1 35 31 30 32 44 19 11 38 10 20 33 15 25 40 48 12 34 28 36 14 8 2 9 24 16 39 17 49 26 41 18 3 4 45 47 6 22 5

output:

44
9 7 5 7 2 7 7 10 3 2 
14 1 1 3 8 2 7 6 1 2 6 1 5 6 1 
5 1 12 9 15 13 
7 13 10 5 9 10 2 1 
3 3 24 23 
4 23 17 7 3 
3 10 39 1 
4 1 37 2 10 
12 2 10 3 6 7 2 2 7 2 2 4 3 
18 3 3 1 2 1 1 7 1 1 2 6 1 6 2 1 3 7 2 
10 2 2 3 2 2 2 9 9 9 10 
15 10 7 2 9 7 2 2 1 1 2 1 2 2 1 1 
5 1 5 9 18 17 
7 17 14 4 9 2 3...

result:

ok OK

Test #7:

score: 0
Accepted
time: 1ms
memory: 4116kb

input:

100
21 42 70 62 37 99 52 55 38 12 95 23 48 18 9 88 30 49 40 60 47 67 27 63 79 75 16 81 22 58 20 2 56 89 76 98 26 14 72 51 7 39 45 54 50 3 13 90 24 33 91 93 15 87 73 25 41 64 29 100 10 28 36 94 46 32 82 61 6 59 69 35 57 80 74 77 17 86 71 66 84 11 96 85 43 65 68 31 44 34 92 1 53 4 97 19 8 78 5 83

output:

58
21 5 5 5 9 3 6 14 3 3 6 4 3 7 4 3 2 8 4 3 2 1 
31 1 1 1 3 1 3 8 1 1 3 3 1 7 1 2 4 1 5 3 1 2 14 1 5 3 1 8 5 1 4 5 
11 9 14 9 17 9 7 9 7 12 5 2 
16 2 2 3 12 4 3 9 2 5 9 4 13 9 2 12 9 
5 21 24 18 14 23 
7 23 4 10 18 5 19 21 
3 40 33 27 
4 27 12 21 40 
3 61 35 4 
4 4 23 12 61 
23 1 4 5 4 2 4 3 3 3 4 ...

result:

ok OK

Test #8:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

120
120 72 23 35 8 87 24 94 101 61 21 18 112 111 73 36 7 105 118 64 40 56 108 1 66 76 77 33 119 53 31 9 89 86 50 96 85 70 30 102 81 13 10 49 78 114 117 57 20 2 98 115 59 43 16 45 63 44 116 54 58 32 68 26 97 5 27 46 4 107 22 95 47 62 17 51 84 74 25 34 104 91 39 106 12 103 79 11 90 109 3 15 88 38 71 4...

output:

60
6 24 26 16 3 22 29 
9 29 21 1 3 15 1 26 23 1 
3 1 50 69 
4 69 48 2 1 
3 3 67 50 
4 50 65 2 3 
34 2 3 5 2 5 5 4 6 4 3 4 5 5 6 2 4 2 3 2 2 3 4 3 2 3 3 2 2 4 4 5 4 3 4 
51 4 2 1 4 3 2 4 3 1 2 1 1 3 2 1 2 2 1 4 1 2 2 1 1 3 1 1 4 1 1 6 4 1 5 3 1 3 2 2 6 3 1 5 3 2 2 2 3 1 2 2 
19 2 2 4 6 9 11 6 9 11 6 ...

result:

ok OK

Test #9:

score: 0
Accepted
time: 1ms
memory: 4148kb

input:

130
64 8 50 36 32 109 91 53 113 19 86 63 4 15 117 46 130 61 72 107 126 31 9 120 87 111 128 94 82 33 45 89 103 29 85 62 98 18 101 73 38 67 77 119 44 105 92 100 40 121 20 57 84 123 114 25 55 95 43 78 11 1 115 90 83 129 52 116 10 65 17 59 7 22 5 122 80 124 118 41 127 58 16 69 88 35 66 106 51 47 3 96 48...

output:

64
34 5 3 2 4 2 7 8 3 4 3 4 4 3 5 2 3 5 2 6 5 3 3 5 8 2 6 2 2 2 4 3 3 3 4 
51 4 1 2 3 1 2 4 1 1 2 1 1 6 1 1 8 2 3 3 1 2 5 1 5 2 4 1 3 1 1 5 1 2 4 3 1 3 3 1 3 6 2 7 1 1 4 1 1 3 1 4 
18 4 5 6 10 10 7 9 7 5 11 8 7 11 8 4 7 6 5 
27 4 1 6 4 3 4 6 2 11 3 4 8 5 6 5 4 3 9 5 2 10 6 4 6 3 2 4 
9 6 13 18 17 15...

result:

ok OK

Test #10:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

200
104 2 22 101 71 156 31 51 154 27 105 102 162 21 113 192 114 64 176 174 198 76 53 6 14 79 130 72 99 38 25 95 175 112 43 39 63 88 187 47 137 77 26 80 56 11 186 151 172 91 144 116 152 55 52 48 199 7 189 98 128 40 178 121 45 32 194 191 134 103 197 82 181 37 59 42 168 61 12 136 115 97 20 180 145 46 1...

output:

88
53 5 3 4 3 3 8 6 6 2 6 4 2 4 2 2 2 4 4 2 4 3 4 4 2 3 3 4 2 5 7 5 2 2 4 5 3 5 2 5 3 4 2 2 4 6 6 4 6 4 3 3 2 5 
79 5 1 1 3 1 2 4 2 4 4 2 4 6 1 3 2 1 1 4 2 1 5 1 1 5 2 1 5 1 3 2 1 1 5 3 4 5 1 1 4 2 1 3 1 1 4 1 3 3 1 3 2 3 1 4 1 1 2 1 1 4 1 1 4 1 5 2 1 5 6 3 5 3 1 2 4 1 2 5 
27 7 7 9 14 8 6 6 4 6 8 7...

result:

ok OK

Test #11:

score: -100
Wrong Answer
time: 2ms
memory: 4228kb

input:

1000
266 497 345 212 566 310 166 640 865 595 225 315 837 619 999 638 652 599 772 515 815 32 416 591 649 476 364 363 915 75 293 569 960 320 545 824 422 433 970 52 894 148 585 713 429 872 330 838 708 257 122 925 100 178 530 17 132 740 40 760 856 712 414 300 296 962 902 424 65 922 733 820 623 295 776 3...

output:

142
14 165 13 16 80 99 19 9 148 77 6 123 98 52 95 
21 95 51 1 98 122 1 6 76 1 148 8 1 19 98 1 80 15 1 13 164 1 
9 1 178 96 118 157 83 221 67 79 
13 79 66 1 221 81 2 157 116 2 96 176 2 1 
5 3 274 275 303 145 
7 145 300 3 275 270 4 3 
3 7 548 445 
4 445 541 7 7 
172 9 5 4 3 4 11 8 10 2 9 3 3 2 10 9 5 ...

result:

wrong answer Integer 142 violates the range [0, 120]