Submission #1049176

#TimeUsernameProblemLanguageResultExecution timeMemory
1049176PoonYaPatDiversity (CEOI21_diversity)C++14
64 / 100
30 ms5600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=300000; int n,q,have[mx+5],res[mx+5]; ll cal(ll x) {return x*(x+1)/2;} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>q; assert(q==1); for (int i=0; i<n; ++i) { int x; cin>>x; ++have[x]; } cin>>q>>q; vector<int> v; for (int i=1; i<=mx; ++i) if (have[i]) v.push_back(have[i]); sort(v.begin(),v.end()); int l=0,r=v.size()-1; for (int i=0; i<(int)(v.size()); ++i) { if (i%2==0) res[l++]=v[i]; else res[r--]=v[i]; } ll ans=(v.size())*cal(n); int sum=0; for (int i=0; i<v.size()-1; ++i) { sum+=res[i]; ans-=cal(sum); } sum=0; for (int i=v.size()-1; i>0; --i) { sum+=res[i]; ans-=cal(sum); } cout<<ans<<"\n"; }

Compilation message (stderr)

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