Submission #549526

#TimeUsernameProblemLanguageResultExecution timeMemory
549526minhcoolDiversity (CEOI21_diversity)C++17
64 / 100
91 ms11828 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 4e5 + 5; const int oo = 1e18 + 7, mod = 1e9 + 7; int n, q, a[N]; ii cnt[N]; void process(){ cin >> n >> q; for(int i = 1; i <= n; i++){ cin >> a[i]; cnt[a[i]].fi++; } for(int i = 1; i <= 300000; i++) cnt[i].se = i; sort(cnt + 1, cnt + 300000 + 1, greater<ii>()); deque<int> dq; for(int i = 1; i <= 300000; i++){ if(i & 1) for(int j = 1; j <= cnt[i].fi; j++) dq.push_front(cnt[i].se); else for(int j = 1; j <= cnt[i].fi; j++) dq.push_back(cnt[i].se); } int cnt = 0, tol = 0, lst = -1, tol2 = 0; //cout << dq.size() << "\n"; while(dq.size()){ int u = dq.front(); //cout << u << "\n"; dq.pop_front(); cnt++; if(lst != u) tol += cnt; else tol++; tol2 += tol; lst = u; } cout << tol2 << "\n"; } signed main(){ ios_base::sync_with_stdio(0); process(); }
#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...