# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090816 | farica | Diversity (CEOI21_diversity) | C++14 | 9 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>
#define ll long long
using namespace std;
const int MAX_N = 3e5;
int b[MAX_N + 5];
void solve() {
int n, q;
cin >> n >> q;
set<int>s;
for(int i=0; i<n; ++i) {
int x;
cin >> x;
++b[x];
s.insert(x);
}
int L, R;
cin >> L >> R;
ll ans = 0, cnt = 0, cnt2 = 0;
vector<int>v;
for(auto it = s.begin(); it != s.end(); ++it) v.push_back(b[*it]);
sort(v.begin(), v.end());
int last = 0;
for(int i=0; i<v.size(); i+=2) {
last = i;
int cur = v[i];
cnt += cnt2;
cnt2 += cur;
ans += (cur * (cur + 1))/2;
ans += cnt * cur;
cnt += cur;
}
if((v.size()-2) == last) ++last;
else --last;
for(int i=last; i>=0; i -= 2) {
int cur = v[i];
cnt += cnt2;
cnt2 += cur;
ans += (cur * (cur + 1))/2;
ans += cnt * cur;
cnt += cur;
}
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
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... |