# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
620802 | berr | Diversity (CEOI21_diversity) | C++17 | 47 ms | 7800 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;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
vector<int> a(300005, 0);
int n, q; cin>>n>>q;
for(int i=0; i<n; i++)
{
int x; cin>>x;
a[x]++;
}
sort(a.begin(), a.end());
int ans=0;
vector<int> b, c;
for(int i=0; i<a.size(); i++)
{
if(a[i]>0)
{
if(i%2) b.push_back(a[i]);
else c.push_back(a[i]);
}
}
int l, r; cin>>l>>r;
reverse(c.begin(), c.end());
for(auto i: c) b.push_back(i);
int sum=0, all=0;
for(int i=0; i<b.size(); i++)
{
sum+=all;
ans+=sum*b[i]+(b[i]*(b[i]+1))/2;
all+=b[i];
sum+=b[i];
}
cout<<ans;
}
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... |