This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while(l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
static int Lamy_is_cute = []() {
EmiliaMyWife
return 48763;
}();
/*--------------------------------------------------------------------------------------*/
signed main() {
int n, m;
cin >> n >> m;
vector<int> arr(n);
for(int &a : arr)
cin >> a;
vector<int> ans(m + 1, INF);
for(int st : {1, 2}) {
vector<int> cnt(m + 1);
vector<map<int, int>> adj(m + 1);
for(int i = 0; i < n; i++)
cnt[arr[i]]++;
for(int i = st; i < n; i += 2) {
int a = arr[i - 1], b = arr[i];
if(a != b) {
adj[a][b]++;
adj[b][a]++;
}
}
multiset<int> has;
for(int i = 1; i <= m; i++)
has.insert(cnt[i]);
has.insert(0);
for(int i = 1; i <= m; i++) {
int res = 0;
has.erase(has.lower_bound(cnt[i]));
for(const auto &[a, c] : adj[i]) {
res = max(res, cnt[a] - c);
has.erase(has.lower_bound(cnt[a]));
}
res = max(res, *has.rbegin());
ans[i] = min(ans[i], n - (res + cnt[i]));
has.insert(cnt[i]);
for(const auto &[a, _] : adj[i])
has.insert(cnt[a]);
}
}
for(int i = 1; i <= m; i++)
cout << ans[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |