Submission #657220

# Submission time Handle Problem Language Result Execution time Memory
657220 2022-11-09T09:06:13 Z dooompy Diversity (CEOI21_diversity) C++17
4 / 100
12 ms 1472 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

int a[300005];
map<int, int> ct;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, q; cin >> n >> q;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ct[a[i]]++;
    }

    vector<pair<int, int>> v;
    for (auto cru : ct) {
        v.push_back({cru.second, cru.first});
    }

    sort(v.begin(), v.end());

    vector<int> st, en;
    for (int i = 0; i < v.size(); i++) {
        if (i % 2 == 0) {
            st.push_back(v[i].first);
        } else en.push_back(v[i].first);
    }

    reverse(en.begin(), en.end());

    for (auto cur : en) st.push_back(cur);

    ll total = n;
    ll ans = 0 ;
    ll before = 0;

    for (auto cur : st) {
        ans += (cur * (cur + 1) / 2);
        ans += (before * cur);
        ans += ((total - cur - before) * cur);
        ans += (before * (total - before - cur));

        before += cur;
    }

    cout << ans;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Incorrect 12 ms 1472 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Incorrect 12 ms 1472 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Incorrect 12 ms 1472 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 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 360 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Incorrect 12 ms 1472 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 360 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Incorrect 12 ms 1472 KB Output isn't correct
16 Halted 0 ms 0 KB -