Submission #1114584

#TimeUsernameProblemLanguageResultExecution timeMemory
1114584vjudge1Diversity (CEOI21_diversity)C++17
0 / 100
2 ms336 KiB
#include <bits/stdc++.h> using i64 = long long; #ifdef DEBUG #include "/home/ahmetalp/Desktop/Workplace/debug.h" #else #define debug(...) void(23) #endif constexpr int max_A = int(3E5) + 5; int cnt[max_A]; i64 calc(std::vector<i64> x) { int n = int(x.size()); i64 ans = 0; for (int i = 0; i < n; ++i) { ans += x[i] * (x[i] + 1) / 2; for (int j = i + 1; j < n; ++j) { ans += x[i] * x[j] * (j - i + 1); } } return ans; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, Q; std::cin >> N >> Q; std::vector<int> A(N); for (int i = 0; i < N; ++i) { std::cin >> A[i]; } std::vector<int> L(Q), R(Q); for (int i = 0; i < Q; ++i) { std::cin >> L[i] >> R[i]; } for (int i = 0; i < N; ++i) { ++cnt[A[i]]; } std::vector<i64> x; for (int i = 0; i < max_A; ++i) { if (cnt[i] != 0) { x.emplace_back(cnt[i]); } } int n = int(x.size()); std::sort(x.begin(), x.end()); std::vector<i64> w(n); int l = 0, r = n - 1; for (int i = 0; i < n; ++i) { if (~i & 1) w[i] = x[l++]; else w[i] = x[r--]; } debug(w); i64 ans = calc(w); 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...