This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pl = pair<ll, ll>;
using vl = V<ll>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
vi A(N); for(auto& x : A) cin >> x;
map<int, int> F; for(auto x : A) F[x]++;
vi C; for(auto& x : F) C.pb(x.s);
int l, r; cin >> l >> r;
assert(l == 1 && r == N);
ll ans = (N * 1LL * (N + 1)) / 2LL;
int M = sz(C); sort(begin(C), end(C));
vi best;
for(int i = 0; i < M; i += 2) best.pb(C[i]);
for(int i = 1; i < M; i += 2) best.pb(C[i]);
int L = 0, R = N;
for(int i = 0; i < M; i++) {
ans += L * 1LL * R;
L += best[i]; R -= best[i];
}
cout << ans << nl;
exit(0-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... |