# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052462 | kunzaZa183 | Diversity (CEOI21_diversity) | C++17 | 4 ms | 860 KiB |
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 namespace std;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n,q;
cin >> n>>q;
vector<int> vi(n);
for (auto &a : vi)
cin >> a;
for(int i=0;i<q;i++)
{
int l,r;
cin>>l>>r;
}
map<int, int> mii;
for (auto a : vi)
mii[a]++;
vector<pair<int, int>> vpii;
for (auto a : mii)
vpii.push_back(a);
sort(vpii.begin(), vpii.end(),
[](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
deque<int> di;
for (int i = 0; i < vpii.size(); i++)
if (i % 2 == 0)
di.push_back(vpii[i].second);
else
di.push_front(vpii[i].second);
int ans = 0;
// for (auto a : di)
// cout << a << ' ';
// cout << "\n";
for (auto a : di)
ans += a * (a + 1) / 2;
// cout << ans << "\n";
for (int i = 0; i < di.size(); i++)
for (int j = i + 1; j < di.size(); j++) {
ans += di[i] * di[j] * (j - i + 1);
}
cout << ans << '\n';
}
Compilation message (stderr)
# | 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... |