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 MAXN 300007
using namespace std;
int n,a[MAXN],q;
int br[MAXN],maxs,l,r,p[MAXN],len;
long long ans;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
br[a[i]]++;
maxs=max(maxs,a[i]);
}
sort(br+1,br+maxs+1);
for(int i=1;i<=maxs;i++){
if(br[i]>0)r++;
}
r++;
len=r-1;
for(int i=1;i<=maxs;i++){
if(br[i]==0)continue;
if(i%2==0){
l++; p[l]=br[i];
}else{
r--; p[r]=br[i];
}
}
for(int i=1;i<=len;i++){
ans+=(long long) (p[i])*(p[i]-1)/2+p[i];
}
for(int i=1;i<=len;i++){
for(int f=i+1;f<=len;f++){
ans+=(long long) p[i]*p[f]*(f-i+1);
}
}
cout<<ans<<"\n";
return 0;
}
# | 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... |