Submission #526303

#TimeUsernameProblemLanguageResultExecution timeMemory
526303keta_tsimakuridzeDiversity (CEOI21_diversity)C++14
64 / 100
138 ms8616 KiB
#include<bits/stdc++.h> #define int long long #define f first #define s second #define pii pair<int,int> using namespace std; const int N = 3e5 + 5, mod = 1e9 + 7; // ! int t, n, a[N], c[N]; 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:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
diversity.cpp: In function 'int main()':
diversity.cpp:22: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]
   22 |  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...