# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871323 | Trisanu_Das | Diversity (CEOI21_diversity) | C++17 | 77 ms | 11060 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>
#define int long long
using namespace std;
const int N = 3e5 + 5, mod = 1e9 + 7;
int t, n, a[300005], c[300005];
signed main(){
int q;
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++;
vector<int> x;
for(int i = 1; i <= n; i++) {
if(!c[a[i]]) continue;
x.push_back(c[a[i]]);
c[a[i]] = 0;
}
sort(x.rbegin(), x.rend());
int t = 0;
deque<int> dq;
for(int i = 0; i < x.size(); i++) {
if(t) dq.push_front(x[i]);
else dq.push_back(x[i]);
t ^= 1;
}
int p = 0, ans = x.size() * n * (n + 1) / 2;
while(dq.size()) {
int x = dq.front();
dq.pop_front();
ans -= (p * (p + 1) / 2);
p += x;
ans -= ((n - p) * (n - p + 1)) / 2;
}
cout << ans;
}
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... |