Submission #871323

#TimeUsernameProblemLanguageResultExecution timeMemory
871323Trisanu_DasDiversity (CEOI21_diversity)C++17
64 / 100
77 ms11060 KiB
#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)

diversity.cpp: In function 'int main()':
diversity.cpp:21:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
#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...