Submission #786048

#TimeUsernameProblemLanguageResultExecution timeMemory
786048OzyDiversity (CEOI21_diversity)C++17
64 / 100
39 ms10568 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define repa(i,a,b) for(int i = (a); i >= (b); i--) #define MAX 300000 lli n,a,res,q; lli arr[MAX+2],vis[MAX+2]; vector<lli> frec; deque<lli> orden; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; rep(i,1,n) { cin >> arr[i]; vis[arr[i]]++; } rep(i,1,n) { if (vis[i] == 0) continue; frec.push_back(vis[i]); vis[i] = 0; } sort(frec.begin(), frec.end()); reverse(frec.begin(), frec.end()); lli x = 0; for(auto act : frec) { if (x) orden.push_back(act); else orden.push_front(act); x ^= 1; } //lee la pregunta lli y; cin >> x >> y; lli sum = 0; lli act,glob = 0; while (!orden.empty()) { act = orden.front(); orden.pop_front(); res += glob*act; x = act*(act+1)/2; res += x; sum += act; glob += sum + act; } cout << res; return 0; }
#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...