Submission #827022

#TimeUsernameProblemLanguageResultExecution timeMemory
827022aminDiversity (CEOI21_diversity)C++14
0 / 100
1 ms280 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int fre[300001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,q; cin>>n>>q; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; fre[a[i]]++; } vector<pair<int,int> >v; for(int i=0;i<n;i++) { if(fre[a[i]]==0) { continue; } v.push_back({fre[a[i]],a[i]}); fre[a[i]]=0; } sort(v.begin(),v.end()); vector<pair<int,int > >s2; vector<pair<int,int > >s1; ll sz1=0,sz2=0; ll k=v.size(); ll ans=n*(n+1)/2*k; ll cursz=0; for(int j=0;j<1000;j++) { cursz=0; for(int i=0;i<v.size()-1;i++) { ll newsz=cursz+v[i].first; ll one=newsz*(newsz+1)/2+(n-newsz)*(n-newsz+1)/2; newsz=v[i+1].first+cursz; ll two=newsz*(newsz+1)/2+(n-newsz)*(n-newsz+1)/2; if(two>one) { swap(v[i],v[i+1]); // cout<<one<<' '<<two<<endl; } cursz+=v[i].first; } } for(auto i:v) { // cout<<i.first<<' '<<i.second<<endl; // if(sz1<=sz2) // { ans-=sz1*(sz1+1)/2; ll j=n-sz1-i.first; ans-=j*(j+1)/2; s1.push_back(i); sz1+=i.first; //}else /* { ans+=sz2*(sz2+1)/2; ll j=n-sz2-i.first; ans-=j*(j+1)/2; s2.push_back(i); sz2+=i.first; }*/ } reverse(s2.begin(),s2.end()); vector<int>b; for(auto i:s1) { while(i.first--) { b.push_back(i.second); } } for(auto i:s2) { while(i.first--) { b.push_back(i.second); } } while(q--) { int l,r; cin>>l>>r; } cout<<ans; }

Compilation message (stderr)

diversity.cpp: In function 'int main()':
diversity.cpp:41:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 | for(int i=0;i<v.size()-1;i++)
      |             ~^~~~~~~~~~~
diversity.cpp:34:10: warning: unused variable 'sz2' [-Wunused-variable]
   34 | ll sz1=0,sz2=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...