Submission #697515

#TimeUsernameProblemLanguageResultExecution timeMemory
697515piOOEDiversity (CEOI21_diversity)C++17
64 / 100
107 ms5584 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> yy = a; sort(yy.begin(), yy.end()); yy.resize(unique(yy.begin(), yy.end()) - yy.begin()); for (int &x : a) { x = lower_bound(yy.begin(), yy.end(), x) - yy.begin(); } const int m = yy.size(); int L, R; cin >> L >> R; assert(q == 1 && L == 1 && R == n); vector<int> cnt(m); for (int x : a) { cnt[x] += 1; } ll ans = 0; for (int x : cnt) { ans += 1LL * x * (x + 1) / 2 + 1LL * x * (n - x); } sort(cnt.begin(), cnt.end()); int l = 0, r = 0; for (int x : cnt) { if (l < r) { ans += 1LL * l * (n - x - l); l += x; } else { ans += 1LL * r * (n - x - r); r += x; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...