# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
837481 |
2023-08-25T11:16:34 Z |
_martynas |
Rope (JOI17_rope) |
C++11 |
|
785 ms |
80596 KB |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e6+5;
int n, m;
int a[mxn], ans[mxn];
int mxcnt = 0;
int cnt[mxn], revcnt[mxn];
vector<vector<int>> where;
void add(int x) {
if(cnt[x] == mxcnt) mxcnt++;
revcnt[cnt[x]]--;
cnt[x]++;
revcnt[cnt[x]]++;
}
void rem(int x) {
if(cnt[x] == mxcnt && revcnt[cnt[x]] == 1) mxcnt--;
revcnt[cnt[x]]--;
cnt[x]--;
revcnt[cnt[x]]++;
}
int main(int argc, char const *argv[]) {
cin >> n >> m;
where.resize(m+1);
for(int i = 0; i < n; i++) cin >> a[i], where[a[i]].push_back(i);
for(int i = 1; i <= m; i++) ans[i] = n;
// skip first
int curr = n;
for(int i = 0; i < n; i++) add(a[i]);
for(int i = 1; i <= m; i++) {
for(int j : where[i]) {
curr--; rem(a[j]);
if(j % 2) {
// from left
if(j == n-1) continue; // not part of a pair
if(a[j+1] != i) rem(a[j+1]);
}
else {
// from right
if(j == 0) continue; // not part of a pair
if(a[j-1] != i) rem(a[j-1]);
}
}
ans[i] = min(ans[i], curr-mxcnt);
for(int j : where[i]) {
curr++; add(a[j]);
if(j % 2) {
// from left
if(j == n-1) continue; // not part of a pair
if(a[j+1] != i) add(a[j+1]);
}
else {
// from right
if(j == 0) continue; // not part of a pair
if(a[j-1] != i) add(a[j-1]);
}
}
}
// pair first
for(int i = 1; i <= m; i++) {
for(int j : where[i]) {
curr--; rem(a[j]);
if(j % 2 == 0) {
// from left
if(j == n-1) continue; // not part of a pair
if(a[j+1] != i) rem(a[j+1]);
}
else {
// from right
if(j == 0) continue; // not part of a pair
if(a[j-1] != i) rem(a[j-1]);
}
}
ans[i] = min(ans[i], curr-mxcnt);
for(int j : where[i]) {
curr++; add(a[j]);
if(j % 2 == 0) {
// from left
if(j == n-1) continue; // not part of a pair
if(a[j+1] != i) add(a[j+1]);
}
else {
// from right
if(j == 0) continue; // not part of a pair
if(a[j-1] != i) add(a[j-1]);
}
}
}
for(int i = 1; i <= m; i++) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
15 ms |
1364 KB |
Output is correct |
28 |
Correct |
16 ms |
1364 KB |
Output is correct |
29 |
Correct |
15 ms |
1364 KB |
Output is correct |
30 |
Correct |
15 ms |
1364 KB |
Output is correct |
31 |
Correct |
15 ms |
1360 KB |
Output is correct |
32 |
Correct |
15 ms |
1364 KB |
Output is correct |
33 |
Correct |
15 ms |
1236 KB |
Output is correct |
34 |
Correct |
16 ms |
1424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
15 ms |
1364 KB |
Output is correct |
28 |
Correct |
16 ms |
1364 KB |
Output is correct |
29 |
Correct |
15 ms |
1364 KB |
Output is correct |
30 |
Correct |
15 ms |
1364 KB |
Output is correct |
31 |
Correct |
15 ms |
1360 KB |
Output is correct |
32 |
Correct |
15 ms |
1364 KB |
Output is correct |
33 |
Correct |
15 ms |
1236 KB |
Output is correct |
34 |
Correct |
16 ms |
1424 KB |
Output is correct |
35 |
Correct |
20 ms |
1236 KB |
Output is correct |
36 |
Correct |
20 ms |
1620 KB |
Output is correct |
37 |
Correct |
21 ms |
1620 KB |
Output is correct |
38 |
Correct |
20 ms |
1620 KB |
Output is correct |
39 |
Correct |
21 ms |
1620 KB |
Output is correct |
40 |
Correct |
20 ms |
1872 KB |
Output is correct |
41 |
Correct |
19 ms |
1696 KB |
Output is correct |
42 |
Correct |
19 ms |
1748 KB |
Output is correct |
43 |
Correct |
19 ms |
1748 KB |
Output is correct |
44 |
Correct |
19 ms |
1748 KB |
Output is correct |
45 |
Correct |
20 ms |
1680 KB |
Output is correct |
46 |
Correct |
21 ms |
1740 KB |
Output is correct |
47 |
Correct |
19 ms |
1740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
15 ms |
1364 KB |
Output is correct |
28 |
Correct |
16 ms |
1364 KB |
Output is correct |
29 |
Correct |
15 ms |
1364 KB |
Output is correct |
30 |
Correct |
15 ms |
1364 KB |
Output is correct |
31 |
Correct |
15 ms |
1360 KB |
Output is correct |
32 |
Correct |
15 ms |
1364 KB |
Output is correct |
33 |
Correct |
15 ms |
1236 KB |
Output is correct |
34 |
Correct |
16 ms |
1424 KB |
Output is correct |
35 |
Correct |
20 ms |
1236 KB |
Output is correct |
36 |
Correct |
20 ms |
1620 KB |
Output is correct |
37 |
Correct |
21 ms |
1620 KB |
Output is correct |
38 |
Correct |
20 ms |
1620 KB |
Output is correct |
39 |
Correct |
21 ms |
1620 KB |
Output is correct |
40 |
Correct |
20 ms |
1872 KB |
Output is correct |
41 |
Correct |
19 ms |
1696 KB |
Output is correct |
42 |
Correct |
19 ms |
1748 KB |
Output is correct |
43 |
Correct |
19 ms |
1748 KB |
Output is correct |
44 |
Correct |
19 ms |
1748 KB |
Output is correct |
45 |
Correct |
20 ms |
1680 KB |
Output is correct |
46 |
Correct |
21 ms |
1740 KB |
Output is correct |
47 |
Correct |
19 ms |
1740 KB |
Output is correct |
48 |
Correct |
222 ms |
15464 KB |
Output is correct |
49 |
Correct |
264 ms |
15508 KB |
Output is correct |
50 |
Correct |
229 ms |
15520 KB |
Output is correct |
51 |
Correct |
213 ms |
15048 KB |
Output is correct |
52 |
Correct |
195 ms |
13712 KB |
Output is correct |
53 |
Correct |
225 ms |
14744 KB |
Output is correct |
54 |
Correct |
215 ms |
13620 KB |
Output is correct |
55 |
Correct |
209 ms |
13516 KB |
Output is correct |
56 |
Correct |
211 ms |
13244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
15 ms |
1364 KB |
Output is correct |
28 |
Correct |
16 ms |
1364 KB |
Output is correct |
29 |
Correct |
15 ms |
1364 KB |
Output is correct |
30 |
Correct |
15 ms |
1364 KB |
Output is correct |
31 |
Correct |
15 ms |
1360 KB |
Output is correct |
32 |
Correct |
15 ms |
1364 KB |
Output is correct |
33 |
Correct |
15 ms |
1236 KB |
Output is correct |
34 |
Correct |
16 ms |
1424 KB |
Output is correct |
35 |
Correct |
20 ms |
1236 KB |
Output is correct |
36 |
Correct |
20 ms |
1620 KB |
Output is correct |
37 |
Correct |
21 ms |
1620 KB |
Output is correct |
38 |
Correct |
20 ms |
1620 KB |
Output is correct |
39 |
Correct |
21 ms |
1620 KB |
Output is correct |
40 |
Correct |
20 ms |
1872 KB |
Output is correct |
41 |
Correct |
19 ms |
1696 KB |
Output is correct |
42 |
Correct |
19 ms |
1748 KB |
Output is correct |
43 |
Correct |
19 ms |
1748 KB |
Output is correct |
44 |
Correct |
19 ms |
1748 KB |
Output is correct |
45 |
Correct |
20 ms |
1680 KB |
Output is correct |
46 |
Correct |
21 ms |
1740 KB |
Output is correct |
47 |
Correct |
19 ms |
1740 KB |
Output is correct |
48 |
Correct |
222 ms |
15464 KB |
Output is correct |
49 |
Correct |
264 ms |
15508 KB |
Output is correct |
50 |
Correct |
229 ms |
15520 KB |
Output is correct |
51 |
Correct |
213 ms |
15048 KB |
Output is correct |
52 |
Correct |
195 ms |
13712 KB |
Output is correct |
53 |
Correct |
225 ms |
14744 KB |
Output is correct |
54 |
Correct |
215 ms |
13620 KB |
Output is correct |
55 |
Correct |
209 ms |
13516 KB |
Output is correct |
56 |
Correct |
211 ms |
13244 KB |
Output is correct |
57 |
Correct |
785 ms |
80596 KB |
Output is correct |
58 |
Correct |
652 ms |
52616 KB |
Output is correct |
59 |
Correct |
710 ms |
52572 KB |
Output is correct |
60 |
Correct |
693 ms |
59672 KB |
Output is correct |
61 |
Correct |
701 ms |
59664 KB |
Output is correct |
62 |
Correct |
390 ms |
34616 KB |
Output is correct |
63 |
Correct |
530 ms |
42708 KB |
Output is correct |
64 |
Correct |
440 ms |
37772 KB |
Output is correct |
65 |
Correct |
310 ms |
24916 KB |
Output is correct |