#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> A(n);
map<int, int> M;
for (int &a : A) cin >> a, M[a] = 0;
int k = 0;
for (auto &p : M) p.second = k++;
vector<LL> cnt(k);
for (int &a : A) a = M[a], ++cnt[a];
int L, R;
cin >> L >> R;
assert(q == 1 && L == 1 && R == n);
LL ans = 0;
for (int c : cnt) ans += c * (c + 1) / 2 + c * (n - c);
sort(cnt.begin(), cnt.end());
// LL l = 0, r = 0, gi = 1;
LL G[2], gi = 0;
for (int c : cnt) {
ans += G[gi] * (n - c - G[gi]), G[gi] += c;
// if (gi)
// ans += l * (n - c - l), l += c;
// else
// ans += r * (n - c - r), r += c;
gi ^= 1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |