# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1185206 | cpdreamer | Diversity (CEOI21_diversity) | C++20 | 202 ms | 16556 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair
#define F first
#define all(v) v.begin(),v.end()
#define V vector
#define pb push_back
#define S second
void file() {
freopen("input.txt.txt", "r", stdin);
freopen("output.txt.txt", "w", stdout);
}
V<int>binary_rep(int n){
V<int>vp;
for(int i=0;i<30;i++){
if(((1<<i)&n)!=0)
vp.pb(1);
else
vp.pb(0);
}
return vp;
}
void solve() {
int n;
cin>>n;
int q;
cin>>q;
int A[n];
map<int,int>mp;
for(int i=0;i<n;i++){
cin>>A[i];
mp[A[i]]++;
}
V<P<int,int>>vp;
for(auto u:mp){
vp.pb({u.S,u.F});
}
sort(all(vp));
reverse(all(vp));
deque<int> b;
for (int j = 0; j < vp.size(); j++) {
P<int, int> u = vp[j];
if(j%2==0) {
for (int i = 0; i < u.F; i++) {
b.pb(u.S);
}
}
else{
for (int i = 0; i < u.F; i++) {
b.push_front(u.S);
}
}
}
mp.clear();
ll s = 0;
ll ans = 0;
for (int i = 0; i < n; i++) {
s -= mp[b[i]];
mp[b[i]] = i + 1;
s += mp[b[i]];
ans += s;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |