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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=300007;
ll n,m,k;
ll a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("output.txt","w",stdout);
// freopen("input.txt","r",stdin);
cin>>n>>m;
for(int i=0;i<n;i++){
int x;
cin>>x;
a[x]++;
}
cin>>m>>m;
vector<ll>d;
for(int i=0;i<N;i++){
if(a[i])d.push_back(a[i]);
}
sort(d.begin(),d.end());
vector<ll>p(d.size(),0);
for(int i=0;i<d.size();i+=2){
p[i/2]=d[i];
if(i+1!=d.size())p[d.size()-i/2-1]=d[i+1];
}
ll ans=0;
ll sum=0;
ll cur=0;
for(int i=0;i<p.size();i++){
sum+=p[i];
cur+=(i+1)*p[i];
}
for(int i=0;i<p.size();i++){
ans+=(p[i]*(p[i]+1))/2;
cur-=p[i];
sum-=p[i];
ans+=p[i]*cur;
cur-=sum;
}
cout<<ans<<endl;
}
Compilation message (stderr)
diversity.cpp: In function 'int main()':
diversity.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<d.size();i+=2){
| ~^~~~~~~~~
diversity.cpp:40:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(i+1!=d.size())p[d.size()-i/2-1]=d[i+1];
| ~~~^~~~~~~~~~
diversity.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
diversity.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
# | 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... |