Submission #670205

# Submission time Handle Problem Language Result Execution time Memory
670205 2022-12-08T09:46:30 Z ymm Rope (JOI17_rope) C++17
100 / 100
1219 ms 202168 KB
///
///   ♪ Hashire sori yo ♪
///   ♪ Kaze no you ni  ♪
///   ♪ Tsukimihara wo  ♪
///   ♪ PADORU PADORU   ♪
///

#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 1<<20;
int a[N];
vector<pii> vec[N];
int n, m;

int cnt[N];
priority_queue<pii> pq;
vector<pii> record;
bool recording;

void add(int c, int x)
{
	if (recording)
		record.push_back({c, cnt[c]});
	cnt[c] += x;
	pq.push({cnt[c], c});
}

void revert()
{
	recording = 0;
	while (record.size()) {
		auto [c, x] = record.back();
		record.pop_back();
		add(c, x-cnt[c]);
	}
}

int get_max()
{
	while (pq.top().first != cnt[pq.top().second])
		pq.pop();
	return pq.top().first;
}

int count(int c, bool odd)
{
	recording = 1;
	int cntc = cnt[c];
	int ans = 0;
	add(c, -cntc);
	vector<pair<pii,bool>> v;
	int lst = 0;
	for (auto [l, r] : vec[c]) {
		if (lst != l)
			v.push_back({{lst, l}, 0});
		v.push_back({{l, r}, 1});
		lst = r;
	}
	if (lst != n)
		v.push_back({{lst, n}, 0});
	for (auto [lr, is] : v) {
		auto [l, r] = lr;
		if (r == n)
			break;
		odd ^= (r - l) & 1;
		if (odd) {
			++cntc;
			++ans;
			add(a[r - 1 + is], -1);
		}
	}
	ans += n - cntc - get_max();
	revert();
	return ans;
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> m;
	Loop (i,0,n) {
		cin >> a[i];
		--a[i];
	}
	int lst = 0;
	Loop (i,0,n) {
		if (a[i] != a[lst]) {
			vec[a[lst]].push_back({lst, i});
			lst = i;
		}
		add(a[i], 1);
	}
	vec[a[lst]].push_back({lst, n});
	Loop (i,0,m) {
		int ans = min(count(i, 0), count(i, 1));
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24916 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 13 ms 24916 KB Output is correct
4 Correct 13 ms 24956 KB Output is correct
5 Correct 14 ms 24912 KB Output is correct
6 Correct 14 ms 24948 KB Output is correct
7 Correct 14 ms 24968 KB Output is correct
8 Correct 14 ms 24960 KB Output is correct
9 Correct 13 ms 24916 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24964 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24960 KB Output is correct
14 Correct 15 ms 24960 KB Output is correct
15 Correct 13 ms 24932 KB Output is correct
16 Correct 14 ms 24916 KB Output is correct
17 Correct 13 ms 24920 KB Output is correct
18 Correct 13 ms 24916 KB Output is correct
19 Correct 13 ms 24964 KB Output is correct
20 Correct 13 ms 24940 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 14 ms 24964 KB Output is correct
23 Correct 13 ms 24956 KB Output is correct
24 Correct 13 ms 24964 KB Output is correct
25 Correct 14 ms 24964 KB Output is correct
26 Correct 14 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24916 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 13 ms 24916 KB Output is correct
4 Correct 13 ms 24956 KB Output is correct
5 Correct 14 ms 24912 KB Output is correct
6 Correct 14 ms 24948 KB Output is correct
7 Correct 14 ms 24968 KB Output is correct
8 Correct 14 ms 24960 KB Output is correct
9 Correct 13 ms 24916 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24964 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24960 KB Output is correct
14 Correct 15 ms 24960 KB Output is correct
15 Correct 13 ms 24932 KB Output is correct
16 Correct 14 ms 24916 KB Output is correct
17 Correct 13 ms 24920 KB Output is correct
18 Correct 13 ms 24916 KB Output is correct
19 Correct 13 ms 24964 KB Output is correct
20 Correct 13 ms 24940 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 14 ms 24964 KB Output is correct
23 Correct 13 ms 24956 KB Output is correct
24 Correct 13 ms 24964 KB Output is correct
25 Correct 14 ms 24964 KB Output is correct
26 Correct 14 ms 24916 KB Output is correct
27 Correct 73 ms 29456 KB Output is correct
28 Correct 62 ms 28732 KB Output is correct
29 Correct 73 ms 29320 KB Output is correct
30 Correct 66 ms 28028 KB Output is correct
31 Correct 72 ms 29292 KB Output is correct
32 Correct 67 ms 28780 KB Output is correct
33 Correct 71 ms 29324 KB Output is correct
34 Correct 64 ms 28004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24916 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 13 ms 24916 KB Output is correct
4 Correct 13 ms 24956 KB Output is correct
5 Correct 14 ms 24912 KB Output is correct
6 Correct 14 ms 24948 KB Output is correct
7 Correct 14 ms 24968 KB Output is correct
8 Correct 14 ms 24960 KB Output is correct
9 Correct 13 ms 24916 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24964 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24960 KB Output is correct
14 Correct 15 ms 24960 KB Output is correct
15 Correct 13 ms 24932 KB Output is correct
16 Correct 14 ms 24916 KB Output is correct
17 Correct 13 ms 24920 KB Output is correct
18 Correct 13 ms 24916 KB Output is correct
19 Correct 13 ms 24964 KB Output is correct
20 Correct 13 ms 24940 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 14 ms 24964 KB Output is correct
23 Correct 13 ms 24956 KB Output is correct
24 Correct 13 ms 24964 KB Output is correct
25 Correct 14 ms 24964 KB Output is correct
26 Correct 14 ms 24916 KB Output is correct
27 Correct 73 ms 29456 KB Output is correct
28 Correct 62 ms 28732 KB Output is correct
29 Correct 73 ms 29320 KB Output is correct
30 Correct 66 ms 28028 KB Output is correct
31 Correct 72 ms 29292 KB Output is correct
32 Correct 67 ms 28780 KB Output is correct
33 Correct 71 ms 29324 KB Output is correct
34 Correct 64 ms 28004 KB Output is correct
35 Correct 48 ms 30788 KB Output is correct
36 Correct 47 ms 30772 KB Output is correct
37 Correct 52 ms 30824 KB Output is correct
38 Correct 46 ms 30908 KB Output is correct
39 Correct 47 ms 30892 KB Output is correct
40 Correct 64 ms 30976 KB Output is correct
41 Correct 65 ms 31032 KB Output is correct
42 Correct 71 ms 28864 KB Output is correct
43 Correct 78 ms 28992 KB Output is correct
44 Correct 54 ms 30948 KB Output is correct
45 Correct 59 ms 31036 KB Output is correct
46 Correct 61 ms 30900 KB Output is correct
47 Correct 63 ms 30996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24916 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 13 ms 24916 KB Output is correct
4 Correct 13 ms 24956 KB Output is correct
5 Correct 14 ms 24912 KB Output is correct
6 Correct 14 ms 24948 KB Output is correct
7 Correct 14 ms 24968 KB Output is correct
8 Correct 14 ms 24960 KB Output is correct
9 Correct 13 ms 24916 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24964 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24960 KB Output is correct
14 Correct 15 ms 24960 KB Output is correct
15 Correct 13 ms 24932 KB Output is correct
16 Correct 14 ms 24916 KB Output is correct
17 Correct 13 ms 24920 KB Output is correct
18 Correct 13 ms 24916 KB Output is correct
19 Correct 13 ms 24964 KB Output is correct
20 Correct 13 ms 24940 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 14 ms 24964 KB Output is correct
23 Correct 13 ms 24956 KB Output is correct
24 Correct 13 ms 24964 KB Output is correct
25 Correct 14 ms 24964 KB Output is correct
26 Correct 14 ms 24916 KB Output is correct
27 Correct 73 ms 29456 KB Output is correct
28 Correct 62 ms 28732 KB Output is correct
29 Correct 73 ms 29320 KB Output is correct
30 Correct 66 ms 28028 KB Output is correct
31 Correct 72 ms 29292 KB Output is correct
32 Correct 67 ms 28780 KB Output is correct
33 Correct 71 ms 29324 KB Output is correct
34 Correct 64 ms 28004 KB Output is correct
35 Correct 48 ms 30788 KB Output is correct
36 Correct 47 ms 30772 KB Output is correct
37 Correct 52 ms 30824 KB Output is correct
38 Correct 46 ms 30908 KB Output is correct
39 Correct 47 ms 30892 KB Output is correct
40 Correct 64 ms 30976 KB Output is correct
41 Correct 65 ms 31032 KB Output is correct
42 Correct 71 ms 28864 KB Output is correct
43 Correct 78 ms 28992 KB Output is correct
44 Correct 54 ms 30948 KB Output is correct
45 Correct 59 ms 31036 KB Output is correct
46 Correct 61 ms 30900 KB Output is correct
47 Correct 63 ms 30996 KB Output is correct
48 Correct 390 ms 108020 KB Output is correct
49 Correct 395 ms 108016 KB Output is correct
50 Correct 398 ms 108104 KB Output is correct
51 Correct 376 ms 108212 KB Output is correct
52 Correct 362 ms 105580 KB Output is correct
53 Correct 553 ms 73636 KB Output is correct
54 Correct 611 ms 55204 KB Output is correct
55 Correct 621 ms 54924 KB Output is correct
56 Correct 655 ms 54444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24916 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 13 ms 24916 KB Output is correct
4 Correct 13 ms 24956 KB Output is correct
5 Correct 14 ms 24912 KB Output is correct
6 Correct 14 ms 24948 KB Output is correct
7 Correct 14 ms 24968 KB Output is correct
8 Correct 14 ms 24960 KB Output is correct
9 Correct 13 ms 24916 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24964 KB Output is correct
12 Correct 13 ms 24916 KB Output is correct
13 Correct 13 ms 24960 KB Output is correct
14 Correct 15 ms 24960 KB Output is correct
15 Correct 13 ms 24932 KB Output is correct
16 Correct 14 ms 24916 KB Output is correct
17 Correct 13 ms 24920 KB Output is correct
18 Correct 13 ms 24916 KB Output is correct
19 Correct 13 ms 24964 KB Output is correct
20 Correct 13 ms 24940 KB Output is correct
21 Correct 14 ms 24916 KB Output is correct
22 Correct 14 ms 24964 KB Output is correct
23 Correct 13 ms 24956 KB Output is correct
24 Correct 13 ms 24964 KB Output is correct
25 Correct 14 ms 24964 KB Output is correct
26 Correct 14 ms 24916 KB Output is correct
27 Correct 73 ms 29456 KB Output is correct
28 Correct 62 ms 28732 KB Output is correct
29 Correct 73 ms 29320 KB Output is correct
30 Correct 66 ms 28028 KB Output is correct
31 Correct 72 ms 29292 KB Output is correct
32 Correct 67 ms 28780 KB Output is correct
33 Correct 71 ms 29324 KB Output is correct
34 Correct 64 ms 28004 KB Output is correct
35 Correct 48 ms 30788 KB Output is correct
36 Correct 47 ms 30772 KB Output is correct
37 Correct 52 ms 30824 KB Output is correct
38 Correct 46 ms 30908 KB Output is correct
39 Correct 47 ms 30892 KB Output is correct
40 Correct 64 ms 30976 KB Output is correct
41 Correct 65 ms 31032 KB Output is correct
42 Correct 71 ms 28864 KB Output is correct
43 Correct 78 ms 28992 KB Output is correct
44 Correct 54 ms 30948 KB Output is correct
45 Correct 59 ms 31036 KB Output is correct
46 Correct 61 ms 30900 KB Output is correct
47 Correct 63 ms 30996 KB Output is correct
48 Correct 390 ms 108020 KB Output is correct
49 Correct 395 ms 108016 KB Output is correct
50 Correct 398 ms 108104 KB Output is correct
51 Correct 376 ms 108212 KB Output is correct
52 Correct 362 ms 105580 KB Output is correct
53 Correct 553 ms 73636 KB Output is correct
54 Correct 611 ms 55204 KB Output is correct
55 Correct 621 ms 54924 KB Output is correct
56 Correct 655 ms 54444 KB Output is correct
57 Correct 1219 ms 202168 KB Output is correct
58 Correct 981 ms 125964 KB Output is correct
59 Correct 975 ms 125844 KB Output is correct
60 Correct 1010 ms 128876 KB Output is correct
61 Correct 1000 ms 129116 KB Output is correct
62 Correct 795 ms 86012 KB Output is correct
63 Correct 860 ms 123400 KB Output is correct
64 Correct 813 ms 121432 KB Output is correct
65 Correct 721 ms 81504 KB Output is correct