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()
{
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;
for (int i = 0; i < v.size(); i++)
for (int j = i + 1; j < v.size(); j++)
ans += (j - i + 1) * v[i] * v[j];
cout << ans;
return 0;
}
Compilation message (stderr)
diversity.cpp: In function 'int main()':
diversity.cpp:22: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]
22 | for (int i = 0; i < poz_fr.size(); i++)
| ~~^~~~~~~~~~~~~~~
diversity.cpp:30: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]
30 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
diversity.cpp:32: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]
32 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
diversity.cpp:33:31: 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 j = i + 1; 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... |