Submission #520456

#TimeUsernameProblemLanguageResultExecution timeMemory
520456KoDDiversity (CEOI21_diversity)C++17
64 / 100
188 ms16436 KiB
#include <bits/stdc++.h> using std::vector; using std::array; using std::pair; using std::tuple; using i64 = std::int64_t; constexpr i64 INF = std::numeric_limits<i64>::max() / 2; template <class T> void setmin(T& lhs, const T& rhs) { if (lhs > rhs) { lhs = rhs; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N, Q; std::cin >> N >> Q; vector<int> A(N); std::map<int, int> count; for (auto& x : A) { std::cin >> x; count[x] += 1; } vector<int> block; for (const auto& [_, c] : count) { block.push_back(c); } std::sort(block.begin(), block.end()); const int n = block.size(); i64 ans = (i64)N * (N + 1) / 2; int left = 0, right = 0; for (int i = 0; i < n - 1; ++i) { if (left < right) { left += block[i]; ans += (i64)left * (N - left); } else { right += block[i]; ans += (i64)right * (N - right); } } std::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...