QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424036 | #962. Thanks to MikeMirzayanov | Hunster | WA | 7ms | 4256kb | C++14 | 3.0kb | 2024-05-28 20:59:11 | 2024-05-28 20:59:12 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int N = 20004;
int n, c[N];
std::vector<std::tuple<int, 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++;
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: 4128kb
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: 3780kb
input:
6 6 5 4 3 2 1
output:
5 2 3 3 2 3 3 4 2 1 2 1 4 1 2 1 2 6 1 1 1 1 1 1
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 1
output:
0
result:
ok OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 4104kb
input:
10 3 8 7 4 6 2 9 10 1 5
output:
8 4 1 3 2 4 6 2 2 2 2 1 1 3 2 6 2 4 2 3 3 2 4 4 1 3 2 6 2 1 2 1 2 2 4 2 3 2 3 6 3 1 1 3 1 1
result:
ok OK
Test #5:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
20 2 13 11 1 19 12 15 3 9 4 14 18 17 7 16 8 6 10 5 20
output:
16 5 1 3 6 4 6 7 6 3 1 6 2 1 1 3 2 9 9 4 9 5 4 2 3 6 13 1 4 1 9 4 6 5 3 2 7 4 4 7 4 1 3 7 1 1 3 6 4 6 3 2 4 1 9 1 2 2 2 1 2 5 1 4 8 2 3 2 6 2 2 2 1 13 1 1 1 1 1 1 1 6 1 1 3 1 1 3 6 3 11 4 11 2 1 6 4 5 2 2 11 6 11 1 1 1 1 5
result:
ok OK
Test #6:
score: 0
Accepted
time: 1ms
memory: 4128kb
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:
30 12 3 4 3 2 7 3 3 3 9 2 6 5 18 5 3 3 2 3 6 3 1 2 3 5 2 2 2 1 4 2 1 7 1 7 6 10 10 8 8 10 8 4 4 10 6 4 6 4 3 1 4 4 14 20 12 6 9 3 20 7 7 4 3 11 30 9 4 9 16 14 11 13 3 2 3 4 4 7 2 2 2 7 3 5 6 20 6 2 3 3 2 5 2 1 1 1 1 7 1 3 4 1 2 2 2 1 9 1 6 8 9 2 8 8 5 3 13 3 4 1 8 2 6 2 5 4 8 3 3 1 5 4 1...
result:
ok OK
Test #7:
score: 0
Accepted
time: 1ms
memory: 3908kb
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:
40 29 2 3 5 5 4 2 2 4 2 3 6 5 4 3 3 4 2 4 3 3 3 5 5 3 5 2 2 3 3 43 3 1 2 2 1 1 5 2 1 5 4 1 3 2 1 3 1 3 2 2 2 3 1 2 4 2 3 6 1 2 2 3 1 2 1 1 4 1 4 5 2 1 2 15 3 11 6 4 7 10 8 6 7 5 6 10 8 5 4 22 4 2 3 8 8 2 6 2 3 7 3 3 8 5 5 7 2 2 6 5 6 3 9 9 13 14 16 13 10 19 5 1 13 1 4 1 19 6 4 13 8 8 14 7 6 9 ...
result:
ok OK
Test #8:
score: 0
Accepted
time: 1ms
memory: 3844kb
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:
44 34 5 2 5 5 5 2 4 4 3 4 5 6 6 2 4 2 5 2 2 3 4 3 2 3 4 2 2 2 2 4 5 5 2 4 51 4 1 1 5 3 2 4 1 1 2 1 1 2 2 2 3 1 1 3 2 2 3 1 1 2 1 4 2 1 3 2 2 4 6 2 3 4 2 1 4 3 1 2 3 2 5 3 2 2 2 3 19 3 6 10 6 8 9 12 7 7 4 6 6 6 5 4 7 9 4 1 28 1 2 2 9 4 3 4 3 2 6 4 2 6 2 2 7 3 4 12 5 4 8 4 2 10 3 3 3 9 6 15 16 21 ...
result:
ok OK
Test #9:
score: 0
Accepted
time: 1ms
memory: 3848kb
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:
46 36 5 3 2 4 2 2 5 8 3 2 2 3 4 4 3 5 2 3 5 8 5 3 3 5 8 2 2 4 2 2 2 4 3 3 3 4 54 3 1 3 1 2 3 3 1 2 1 1 2 3 1 2 1 1 8 2 3 3 1 2 5 1 7 5 1 2 2 3 2 3 3 1 4 2 1 2 1 1 3 6 2 5 1 1 2 1 3 2 2 1 5 19 6 7 4 8 10 4 7 8 7 13 8 7 11 4 6 4 8 5 3 28 3 2 3 8 2 2 6 2 2 11 3 4 8 5 8 7 4 4 7 2 2 10 4 4 4 3 4 6 9 ...
result:
ok OK
Test #10:
score: 0
Accepted
time: 1ms
memory: 4120kb
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:
50 52 3 2 3 2 4 4 8 6 6 2 6 4 6 2 2 2 4 6 4 3 4 3 6 3 4 2 5 7 5 2 2 4 2 3 3 5 2 5 3 4 2 6 6 5 4 7 4 3 3 2 4 1 78 1 1 3 2 2 1 3 1 3 7 3 1 5 4 2 6 1 1 4 2 1 5 1 1 5 2 1 3 1 1 4 1 1 2 1 4 7 4 1 2 1 3 3 5 1 3 2 2 3 1 3 6 2 2 2 1 1 2 3 3 4 1 5 2 2 4 6 3 5 4 3 1 2 1 2 2 1 2 27 2 5 4 12 13 9 8 6 5 11 6 6...
result:
ok OK
Test #11:
score: 0
Accepted
time: 2ms
memory: 4256kb
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:
88 253 4 3 5 11 5 3 3 4 2 2 3 2 4 3 3 2 6 4 5 2 2 7 4 7 6 3 5 5 3 2 2 7 4 6 4 3 9 2 4 2 4 2 9 3 5 8 3 2 6 4 5 2 2 2 2 5 3 2 4 4 2 5 4 2 2 2 3 3 2 3 7 3 3 11 5 3 2 4 3 2 2 4 9 3 3 4 6 2 5 3 4 4 4 3 4 3 2 5 2 5 6 5 9 5 7 2 2 5 5 5 7 2 3 3 3 7 5 3 2 5 2 5 3 7 6 3 3 2 5 2 11 4 2 4 2 2 3 4 2 2 4 2 4 6 3 ...
result:
ok OK
Test #12:
score: -100
Wrong Answer
time: 7ms
memory: 4184kb
input:
3535 3521 780 1120 790 540 803 1342 3087 280 382 938 2398 1467 1959 645 1259 371 830 3399 1237 3356 3533 903 1721 2564 1545 3222 1184 1473 1970 1483 609 3349 571 536 591 1598 2380 1993 2527 71 1303 2278 1233 264 1262 3428 2133 307 1793 2678 2857 3029 3149 2197 876 1621 1418 1802 111 1394 406 3422 27...
output:
124 882 7 4 2 5 2 4 2 3 3 5 5 4 3 9 4 4 3 6 4 2 7 3 3 4 2 3 2 9 5 2 6 3 2 2 3 7 5 3 3 2 2 2 5 4 4 2 4 3 6 8 8 3 7 4 3 4 2 4 3 3 2 3 7 7 5 5 4 4 6 2 9 4 7 3 2 4 4 5 4 2 2 6 7 6 6 2 3 2 4 2 2 2 4 3 3 3 4 2 3 3 3 5 2 5 3 3 2 2 3 5 4 2 9 2 2 2 5 6 3 3 4 4 2 4 2 3 7 4 3 7 4 3 6 2 2 2 6 3 2 2 2 3 3 5 9 3 ...
result:
wrong answer Integer 124 violates the range [0, 120]