답안 #988797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988797 2024-05-26T08:15:21 Z LOLOLO Diversity (CEOI21_diversity) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 10;
int cnt[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;

    assert(q == 1);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    vector <ll> val;
    for (int i = 1; i < N; i++) {
        if (cnt[i])
            val.pb(cnt[i]);
    }

    int l, r;
    cin >> l >> r;

    sort(all(val), greater <ll> ());
    deque <ll> dq;
    int odd = 0;
    ll ans = 0;

    for (auto x : val) {
        if (odd == 0) {
            dq.pb(x);
        } else {
            dq.push_front(x);
        }

        odd = 1 - odd;
        ans += x * (x + 1) / 2;
    } 

    ll sum = 0, ind = 0;
    while (sz(dq)) {
        ll t = dq.front();
        dq.pop_front();
        ans += (t * (ind + 1) * ind - sum);
        sum += t * ind;
        ind++;
    }

    cout << ans << '\n';
    return 0;
} 

// (n + ) * n 
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -