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 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 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |