# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
489299 |
2021-11-22T07:25:21 Z |
cheissmart |
Rope (JOI17_rope) |
C++14 |
|
1460 ms |
96268 KB |
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emaplce_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
const int INF = 1e9 + 7, N = 1e6 + 7;
void cmin(int& a, int b) {
a = min(a, b);
}
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
vi a(n), ans(m, INF);
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
auto go = [&] (V<array<int, 2>> x) {
vi cnt(m), cnt2(n + 1);
cnt2[0] = m;
int cur_sum = 0, cur_mx = 0;
auto add = [&] (int e) {
cur_sum++;
cnt2[cnt[e]]--;
cnt[e]++;
cnt2[cnt[e]]++;
cur_mx = max(cur_mx, cnt[e]);
};
auto del = [&] (int e) {
cur_sum--;
cnt2[cnt[e]]--;
cnt[e]--;
cnt2[cnt[e]]++;
if(cnt2[cur_mx] == 0)
cur_mx--;
};
V<V<array<int, 2>>> pos(m);
for(auto e:x) {
pos[e[0]].PB(e), add(e[0]);
if(e[0] == e[1]) add(e[1]);
else if(e[1] != -1) pos[e[1]].PB(e), add(e[1]);
}
for(int i = 0; i < m; i++) {
int cost = 0;
for(auto e:pos[i]) {
del(e[0]), cost += e[0] != i;
if(e[1] != -1) del(e[1]), cost += e[1] != i;
}
cost += cur_sum - cur_mx;
ans[i] = min(ans[i], cost);
for(auto e:pos[i]) {
add(e[0]);
if(e[1] != -1) add(e[1]);
}
}
};
V<array<int, 2>> x, y;
for(int i = 0; i < n; i += 2) {
array<int, 2> tt;
tt[0] = a[i], tt[1] = -1;
if(i + 1 < n) tt[1] = a[i + 1];
x.PB(tt);
}
y.PB({a[0], -1});
for(int i = 1; i < n; i += 2) {
array<int, 2> tt;
tt[0] = a[i], tt[1] = -1;
if(i + 1 < n) tt[1] = a[i + 1];
y.PB(tt);
}
go(x), go(y);
for(int i = 0; i < m; i++)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
308 KB |
Output is correct |
27 |
Correct |
16 ms |
4104 KB |
Output is correct |
28 |
Correct |
16 ms |
4032 KB |
Output is correct |
29 |
Correct |
16 ms |
3900 KB |
Output is correct |
30 |
Correct |
16 ms |
4172 KB |
Output is correct |
31 |
Correct |
18 ms |
4052 KB |
Output is correct |
32 |
Correct |
20 ms |
4160 KB |
Output is correct |
33 |
Correct |
17 ms |
3980 KB |
Output is correct |
34 |
Correct |
18 ms |
4220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
308 KB |
Output is correct |
27 |
Correct |
16 ms |
4104 KB |
Output is correct |
28 |
Correct |
16 ms |
4032 KB |
Output is correct |
29 |
Correct |
16 ms |
3900 KB |
Output is correct |
30 |
Correct |
16 ms |
4172 KB |
Output is correct |
31 |
Correct |
18 ms |
4052 KB |
Output is correct |
32 |
Correct |
20 ms |
4160 KB |
Output is correct |
33 |
Correct |
17 ms |
3980 KB |
Output is correct |
34 |
Correct |
18 ms |
4220 KB |
Output is correct |
35 |
Correct |
18 ms |
4180 KB |
Output is correct |
36 |
Correct |
18 ms |
4240 KB |
Output is correct |
37 |
Correct |
18 ms |
4092 KB |
Output is correct |
38 |
Correct |
19 ms |
4108 KB |
Output is correct |
39 |
Correct |
18 ms |
4188 KB |
Output is correct |
40 |
Correct |
17 ms |
4348 KB |
Output is correct |
41 |
Correct |
19 ms |
4292 KB |
Output is correct |
42 |
Correct |
19 ms |
4300 KB |
Output is correct |
43 |
Correct |
19 ms |
4300 KB |
Output is correct |
44 |
Correct |
19 ms |
4324 KB |
Output is correct |
45 |
Correct |
19 ms |
4292 KB |
Output is correct |
46 |
Correct |
19 ms |
4188 KB |
Output is correct |
47 |
Correct |
18 ms |
4296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
308 KB |
Output is correct |
27 |
Correct |
16 ms |
4104 KB |
Output is correct |
28 |
Correct |
16 ms |
4032 KB |
Output is correct |
29 |
Correct |
16 ms |
3900 KB |
Output is correct |
30 |
Correct |
16 ms |
4172 KB |
Output is correct |
31 |
Correct |
18 ms |
4052 KB |
Output is correct |
32 |
Correct |
20 ms |
4160 KB |
Output is correct |
33 |
Correct |
17 ms |
3980 KB |
Output is correct |
34 |
Correct |
18 ms |
4220 KB |
Output is correct |
35 |
Correct |
18 ms |
4180 KB |
Output is correct |
36 |
Correct |
18 ms |
4240 KB |
Output is correct |
37 |
Correct |
18 ms |
4092 KB |
Output is correct |
38 |
Correct |
19 ms |
4108 KB |
Output is correct |
39 |
Correct |
18 ms |
4188 KB |
Output is correct |
40 |
Correct |
17 ms |
4348 KB |
Output is correct |
41 |
Correct |
19 ms |
4292 KB |
Output is correct |
42 |
Correct |
19 ms |
4300 KB |
Output is correct |
43 |
Correct |
19 ms |
4300 KB |
Output is correct |
44 |
Correct |
19 ms |
4324 KB |
Output is correct |
45 |
Correct |
19 ms |
4292 KB |
Output is correct |
46 |
Correct |
19 ms |
4188 KB |
Output is correct |
47 |
Correct |
18 ms |
4296 KB |
Output is correct |
48 |
Correct |
200 ms |
41628 KB |
Output is correct |
49 |
Correct |
210 ms |
41564 KB |
Output is correct |
50 |
Correct |
211 ms |
41636 KB |
Output is correct |
51 |
Correct |
216 ms |
41188 KB |
Output is correct |
52 |
Correct |
176 ms |
38448 KB |
Output is correct |
53 |
Correct |
189 ms |
40080 KB |
Output is correct |
54 |
Correct |
189 ms |
37924 KB |
Output is correct |
55 |
Correct |
180 ms |
37548 KB |
Output is correct |
56 |
Correct |
208 ms |
37160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
308 KB |
Output is correct |
27 |
Correct |
16 ms |
4104 KB |
Output is correct |
28 |
Correct |
16 ms |
4032 KB |
Output is correct |
29 |
Correct |
16 ms |
3900 KB |
Output is correct |
30 |
Correct |
16 ms |
4172 KB |
Output is correct |
31 |
Correct |
18 ms |
4052 KB |
Output is correct |
32 |
Correct |
20 ms |
4160 KB |
Output is correct |
33 |
Correct |
17 ms |
3980 KB |
Output is correct |
34 |
Correct |
18 ms |
4220 KB |
Output is correct |
35 |
Correct |
18 ms |
4180 KB |
Output is correct |
36 |
Correct |
18 ms |
4240 KB |
Output is correct |
37 |
Correct |
18 ms |
4092 KB |
Output is correct |
38 |
Correct |
19 ms |
4108 KB |
Output is correct |
39 |
Correct |
18 ms |
4188 KB |
Output is correct |
40 |
Correct |
17 ms |
4348 KB |
Output is correct |
41 |
Correct |
19 ms |
4292 KB |
Output is correct |
42 |
Correct |
19 ms |
4300 KB |
Output is correct |
43 |
Correct |
19 ms |
4300 KB |
Output is correct |
44 |
Correct |
19 ms |
4324 KB |
Output is correct |
45 |
Correct |
19 ms |
4292 KB |
Output is correct |
46 |
Correct |
19 ms |
4188 KB |
Output is correct |
47 |
Correct |
18 ms |
4296 KB |
Output is correct |
48 |
Correct |
200 ms |
41628 KB |
Output is correct |
49 |
Correct |
210 ms |
41564 KB |
Output is correct |
50 |
Correct |
211 ms |
41636 KB |
Output is correct |
51 |
Correct |
216 ms |
41188 KB |
Output is correct |
52 |
Correct |
176 ms |
38448 KB |
Output is correct |
53 |
Correct |
189 ms |
40080 KB |
Output is correct |
54 |
Correct |
189 ms |
37924 KB |
Output is correct |
55 |
Correct |
180 ms |
37548 KB |
Output is correct |
56 |
Correct |
208 ms |
37160 KB |
Output is correct |
57 |
Correct |
1460 ms |
96268 KB |
Output is correct |
58 |
Correct |
1084 ms |
69812 KB |
Output is correct |
59 |
Correct |
1040 ms |
69564 KB |
Output is correct |
60 |
Correct |
1191 ms |
76016 KB |
Output is correct |
61 |
Correct |
1251 ms |
76140 KB |
Output is correct |
62 |
Correct |
495 ms |
55444 KB |
Output is correct |
63 |
Correct |
651 ms |
62392 KB |
Output is correct |
64 |
Correct |
549 ms |
58148 KB |
Output is correct |
65 |
Correct |
286 ms |
47116 KB |
Output is correct |