이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000000, M = 10000000;
int a[N], ans[M], cnt[M];
vector<int> g[N];
priority_queue<pair<int, int>> pq;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(ans, 0x3f, sizeof(ans));
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
--a[i];
++cnt[a[i]];
}
for (int i = 0; i < m; ++i) {
pq.push({cnt[i], i});
}
for (int k = 0; k < 2; ++k) {
for (int i = 0; i < m; ++i) {
g[i].clear();
}
for (int i = k; i + 1 < n; i += 2) {
if (a[i] != a[i + 1]) {
g[a[i]].push_back(a[i + 1]);
g[a[i + 1]].push_back(a[i]);
}
}
for (int c = 0; c < m; ++c) {
int now = cnt[c];
auto upd = [](int v, int nw) {
pq.push({cnt[v] = nw, v});
};
upd(c, 0);
for (int to : g[c]) {
upd(to, cnt[to] - 1);
}
while (cnt[pq.top().second] != pq.top().first) {
pq.pop();
}
ans[c] = min(ans[c], n - now - pq.top().first);
upd(c, now);
for (int to : g[c]) {
upd(to, cnt[to] + 1);
}
}
}
for (int i = 0; i < m; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# | 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... |