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 ar array
#define int long long
#define bug(x) cerr << #x << ' ' << x << '\n';
const int N = 3e5 + 5;
int a[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, q; cin>>n>>q;
for(int i=0;i<n;i++) cin>>a[i];
sort(a, a + n);
int tot = 0, res = 0;
for(int i=0;i<n;){
int j = i;
while(j<n && a[j] == a[i]) j++;
tot++;
res -= i * (i + 1);
//~ cout<<i<<" "<<n - j<<"\n";
res -= (n - j) * (n - j + 1);
i = j;
}
//~ cout<<tot<<" "<<res<<"\n";
res += tot * n * (n + 1);
res /= 2;
cout<<res<<"\n";
}
# | 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... |