Submission #988798

#TimeUsernameProblemLanguageResultExecution timeMemory
988798LOLOLODiversity (CEOI21_diversity)C++17
64 / 100
27 ms7376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 3e5 + 10; int cnt[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; assert(q == 1); for (int i = 1; i <= n; i++) { int x; cin >> x; cnt[x]++; } vector <ll> val; for (int i = 1; i < N; i++) { if (cnt[i]) val.pb(cnt[i]); } int l, r; cin >> l >> r; sort(all(val), greater <ll> ()); deque <ll> dq; int odd = 0; ll ans = 0; for (auto x : val) { if (odd == 0) { dq.pb(x); } else { dq.push_front(x); } odd = 1 - odd; ans += x * (x + 1) / 2; } ll sum = 0, nor = 0; while (sz(dq)) { ll t = dq.front(); dq.pop_front(); sum += nor; ans += (t * sum); nor += t; sum += t; } cout << ans << '\n'; return 0; } // (n + ) * n
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...