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>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 200005
using namespace std;
void solve(){
int n,q; cin >> n >> q;
int arr[n+1];
map<int, int> cnt;
for(int i=1; i<=n; i++){
cin >> arr[i];
cnt[arr[i]]++;
}
for(int i=1; i<=q; i++){int a,b; cin >> a >> b;}
vi wow;
for(auto p:cnt) wow.pb(p.nd);
sort(all(wow));
int p1=0, p2=0, ans=n*(n+1)/2;
for(int i=0; i<wow.size()-1; i++){
if(p1>p2) swap(p1,p2);
p1+=wow[i];
ans+=p1*(n-p1);
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
/*#else
freopen("248.in","r",stdin);
freopen("248.out","w",stdout);*/
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
Compilation message (stderr)
diversity.cpp: In function 'void solve()':
diversity.cpp:33:19: 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<wow.size()-1; 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... |