Submission #576336

#TimeUsernameProblemLanguageResultExecution timeMemory
576336amunduzbaevDiversity (CEOI21_diversity)C++17
64 / 100
74 ms10988 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long const int N = 3e5 + 5; int cc[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, q; cin>>n>>q; vector<int> a(n), b; for(int i=0;i<n;i++) cin>>a[i]; b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); int m = b.size(); for(int i=0;i<n;i++){ cc[a[i]]++; } sort(b.begin(), b.end(), [&](int i, int j){ return (cc[i] > cc[j]); }); deque<int> c; for(int i=0;i<m;i++){ if(i & 1) c.push_back(cc[b[i]]); else c.push_front(cc[b[i]]); } //~ for(int i=0;i<n;i++) cout<<c[i]<<" "; //~ cout<<"\n"; int res = n * (n + 1) / 2; int ajj = 0, aj = 0; for(int i=0;i<m;i++){ res = res + c[i] * i * aj - c[i] * ajj; aj += c[i]; ajj += c[i] * i; } cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...