This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
const int N = 100005;
int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i], cnt[a[i]]++, p[a[i]].push_back(i);
}
set<ii> s;
for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
for (int i = 1; i <= m; ++i) {
res[i] = 1e9;
for (int j = 0; j < 2; ++j) {
vector<int> go;
int sum = 0;
for (int k = 0; k < p[i].size(); ++k) {
if (p[i][k] % 2 == j) {
int cur = a[p[i][k] - 1];
if (p[i][k] > 1 && cur != i) {
if (++val[cur] == 1) go.push_back(cur);
}
}
else {
int cur = a[p[i][k] + 1];
if (p[i][k] < n && cur != i) {
if (++val[cur] == 1) go.push_back(cur);
}
}
}
for (int k = 0; k < go.size(); ++k) {
s.erase(s.find(ii(cnt[go[k]], go[k])));
s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
}
s.erase(s.find(ii(cnt[i], i)));
res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
for (int k = 0; k < go.size(); ++k) {
s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
s.insert(ii(cnt[go[k]], go[k]));
}
s.insert(ii(cnt[i], i));
for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
}
cout << res[i] << '\n';
}
}
Compilation message (stderr)
rope.cpp: In function 'int main()':
rope.cpp:25:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < p[i].size(); ++k) {
^
rope.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) {
^
rope.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) {
^
rope.cpp:50:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
^
rope.cpp:24:8: warning: unused variable 'sum' [-Wunused-variable]
int sum = 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... |