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
int n,a[300005],fr[300005],q,l1,r1;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i],fr[a[i]]++;
cin >> l1 >> r1;
vector<int> poz_fr;
for (int i = 1; i <= 300000; i++)
//if (fr[i] > 0)
poz_fr.push_back(fr[i]);
sort(poz_fr.begin(),poz_fr.end());
vector<int> v(poz_fr.size());
l1 = 0,r1 = poz_fr.size() - 1;
for (int i = 0; i < poz_fr.size(); i++)
{
if (i % 2 == 0)
v[l1] = poz_fr[i],l1++;
else
v[r1] = poz_fr[i],r1--;
}
int ans = 0;
for (int i = 0; i < v.size(); i++)
ans += v[i] * (v[i] + 1) / 2;
int sumvi = 0,sumivi = 0;
for (int j = 0; j < v.size(); j++)
{
ans += j * v[j] * sumvi - v[j] * sumivi + sumvi * v[j];
sumvi += v[j];
sumivi += j * v[j];
}
cout << ans;
return 0;
}
Compilation message (stderr)
diversity.cpp: In function 'int main()':
diversity.cpp:25:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < poz_fr.size(); i++)
| ~~^~~~~~~~~~~~~~~
diversity.cpp:33:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
diversity.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
# | 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... |