| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 708153 | vjudge1 | Diversity (CEOI21_diversity) | C++11 | 0 ms | 0 KiB |
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;
using LL = long long;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> A(n);
map<int, int> M;
for (int &a : A) cin >> a, M[a] = 0;
int k = 0;
for (auto &p : M) p.second = k++;
vector<LL> cnt(k);
for (int &a : A) a = M[a], ++cnt[a];
int L, R;
cin >> L >> R;
assert(q == 1 && L == 1 && R == n);
LL ans = 0;
for (int c : cnt) ans += c * (c + 1) / 2 + c * (n - c);
sort(cnt.begin(), cnt.end());
LL l = 0, r = 0, gi = 1;
LL G[2], gi = 0;
for (int c : cnt) {
ans += G[gi] * (n - c - G[gi]), G[gi] += c;
// if (gi)
// ans += l * (n - c - l), l += c;
// else
// ans += r * (n - c - r), r += c;
gi ^= 1;
}
cout << ans << '\n';
return 0;
}
