Submission #1114584

# Submission time Handle Problem Language Result Execution time Memory
1114584 2024-11-19T08:14:04 Z vjudge1 Diversity (CEOI21_diversity) C++17
0 / 100
2 ms 336 KB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

constexpr int max_A = int(3E5) + 5;

int cnt[max_A];

i64 calc(std::vector<i64> x) {
    int n = int(x.size());
    i64 ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += x[i] * (x[i] + 1) / 2;
        for (int j = i + 1; j < n; ++j) {
            ans += x[i] * x[j] * (j - i + 1);
        }
    }
    return ans;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N, Q;
    std::cin >> N >> Q;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    std::vector<int> L(Q), R(Q);
    for (int i = 0; i < Q; ++i) {
        std::cin >> L[i] >> R[i];
    }

    for (int i = 0; i < N; ++i) {
        ++cnt[A[i]];
    }

    std::vector<i64> x;
    for (int i = 0; i < max_A; ++i) {
        if (cnt[i] != 0) {
            x.emplace_back(cnt[i]);
        }
    }

    int n = int(x.size());

    std::sort(x.begin(), x.end());

    std::vector<i64> w(n);
    int l = 0, r = n - 1;
    for (int i = 0; i < n; ++i) {
        if (~i & 1) w[i] = x[l++];
        else w[i] = x[r--];
    }

    debug(w);

    i64 ans = calc(w);
    std::cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -