Submission #1090816

#TimeUsernameProblemLanguageResultExecution timeMemory
1090816faricaDiversity (CEOI21_diversity)C++14
4 / 100
9 ms860 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAX_N = 3e5; int b[MAX_N + 5]; void solve() { int n, q; cin >> n >> q; set<int>s; for(int i=0; i<n; ++i) { int x; cin >> x; ++b[x]; s.insert(x); } int L, R; cin >> L >> R; ll ans = 0, cnt = 0, cnt2 = 0; vector<int>v; for(auto it = s.begin(); it != s.end(); ++it) v.push_back(b[*it]); sort(v.begin(), v.end()); int last = 0; for(int i=0; i<v.size(); i+=2) { last = i; int cur = v[i]; cnt += cnt2; cnt2 += cur; ans += (cur * (cur + 1))/2; ans += cnt * cur; cnt += cur; } if((v.size()-2) == last) ++last; else --last; for(int i=last; i>=0; i -= 2) { int cur = v[i]; cnt += cnt2; cnt2 += cur; ans += (cur * (cur + 1))/2; ans += cnt * cur; cnt += cur; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while(t--) solve(); return 0; }

Compilation message (stderr)

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