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 ll long long
const int N = 300'005;
int a[N], frq[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
frq[a[i]]++;
}
vector<int> v;
for (int i = 0; i < N; i++) {
if (frq[i]) {
v.push_back(frq[i]);
}
}
n = v.size();
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += v[i] * (v[i] + 1) / 2;
for (int j = i + 1; j < n; j++) {
ans += 1ll * v[i] * v[j] * (j - 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... |