# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713235 | Pacybwoah | Diversity (CEOI21_diversity) | C++14 | 99 ms | 13276 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<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
ll n,q;
cin>>n>>q;
if(q!=1) return 0;
int a,b;
vector<ll> vec(n);
for(int i=0;i<n;i++) cin>>vec[i];
cin>>a>>b;
vector<ll> cnt(300001);
for(int i=0;i<n;i++) cnt[vec[i]]++;
vector<ll> p;
for(int i=0;i<=300000;i++){
if(cnt[i]>0) p.push_back(cnt[i]);
}
sort(p.begin(),p.end());
vector<ll> f;
for(int i=0;i<p.size();i+=2){
f.push_back(p[i]);
}
for(int i=(p.size()%2==0?p.size()-1:p.size()-2);i>=0;i-=2) f.push_back(p[i]);
ll sum=0,len=f.size();
vector<ll> pre1(len),pre2(len);
for(int i=1;i<len;i++){
pre1[i]=pre1[i-1]+f[i]*i;
pre2[i]=pre2[i-1]+f[i];
}
for(ll i=0;i<len;i++){
sum+=f[i]*(f[i]+1)/2;
sum+=f[i]*(pre1[len-1]-pre1[i]-(i-1)*(pre2[len-1]-pre2[i]));
}
cout<<sum<<"\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... |