# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049176 | PoonYaPat | Diversity (CEOI21_diversity) | C++14 | 30 ms | 5600 KiB |
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;
const int mx=300000;
int n,q,have[mx+5],res[mx+5];
ll cal(ll x) {return x*(x+1)/2;}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>q;
assert(q==1);
for (int i=0; i<n; ++i) {
int x; cin>>x;
++have[x];
}
cin>>q>>q;
vector<int> v;
for (int i=1; i<=mx; ++i) if (have[i]) v.push_back(have[i]);
sort(v.begin(),v.end());
int l=0,r=v.size()-1;
for (int i=0; i<(int)(v.size()); ++i) {
if (i%2==0) res[l++]=v[i];
else res[r--]=v[i];
}
ll ans=(v.size())*cal(n);
int sum=0;
for (int i=0; i<v.size()-1; ++i) {
sum+=res[i];
ans-=cal(sum);
}
sum=0;
for (int i=v.size()-1; i>0; --i) {
sum+=res[i];
ans-=cal(sum);
}
cout<<ans<<"\n";
}
Compilation message (stderr)
# | 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... |