# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
827022 | 2023-08-16T08:03:53 Z | amin | Diversity (CEOI21_diversity) | C++14 | 1 ms | 280 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 280 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 280 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 280 KB | Output is correct |
5 | Incorrect | 0 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |