이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// -- -- ---- --- -- --
/// no. c.ompi le ti:me
/// -- -- ---- --- -- --
#include <bits/stdc++.h>
using namespace std;
void abandoned_precalc();
#define pll pair<long long, long long>
#define all(a) (a).begin(), (a).end()
#define len(a) ((int)(a).size())
#define add push_back
#define mkp make_pair
#define ll long long
#define fr first
#define sc second
const long long INF = 1000000000ll * 1000000003ll;
const long long MOD = 1000000007ll;
const int N = 3e5 + 5;
ll n, q;
ll a[N];
ll cnt[N];
void solve(){
cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> a[i];
cnt[a[i]]++;
}
for(int i = 0, x, y; i < q; i++){
cin >> x >> y;
}
vector<ll> v, w;
for(int i = 1; i <= 300000; i++){
if(cnt[i]) v.add(cnt[i]);
}
sort(all(v));
for(int i = 0; i < len(v); i++){
if(i < len(v) / 2) w.add(v[2 * i + 1]);
else w.add(v[(len(v) - 1 - i) * 2]);
}
// for(auto x : w){
// cout << x << " ";
// }
// cout << endl;
ll ans = 0;
for(int i = 0; i < len(w); i++){
ans += w[i] * (w[i] + 1) / 2;
for(int j = i + 1; j < len(w); j++){
ans += (j - i + 1) * (w[i] * w[j]);
}
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int _ = 1;
// cout << fixed;
// cout.precision(9);
abandoned_precalc();
// cin >> _ ;
while(_--) solve();
return 0;
}
/// ---- - -------- ------ -------- -- - - -
/// just a reminder. ubuntu password is i o i
/// ---- - -------- ------ -------- -- - - -
void abandoned_precalc(){
}
# | 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... |