# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708153 | 2023-03-11T07:16:50 Z | vjudge1 | Diversity (CEOI21_diversity) | C++11 | 0 ms | 0 KB |
#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; }