Submission #495601

# Submission time Handle Problem Language Result Execution time Memory
495601 2021-12-19T12:52:48 Z Victor Diversity (CEOI21_diversity) C++17
64 / 100
110 ms 14124 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

int n, arr[300001], q;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    umap<int, int> ttoi;
    vii types;
    cin >> n >> q;
    rep(i, 0, n) {
        int type;
        cin >> type;

        if (!ttoi.count(type)) {
            types.emplace_back(0, sz(ttoi));
            ttoi[type] = sz(types) - 1;
        }
        ++types[ttoi[type]].first;
    }

    sort(all(types));
    n = sz(types);
    int lo = 0, hi = n - 1;
    bool side = 0;

    ll ans = 0;
    trav(item, types) {
        int type, cnt;
        tie(cnt, type) = item;

        if (side)
            arr[hi--] = cnt;
        else
            arr[lo++] = cnt;
        side ^= 1;
        ans += ll(cnt) * (cnt + 1) / 2;
    }

    if (q == 1) {

        ll prefix=0,fac=0;
        rep(i, 0, n){
            ans+=arr[i]*fac;
            prefix+=arr[i];
            fac+=prefix+arr[i];
        }
        cout << ans << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 6 ms 204 KB Output is correct
5 Correct 13 ms 324 KB Output is correct
6 Correct 18 ms 204 KB Output is correct
7 Correct 20 ms 204 KB Output is correct
8 Correct 19 ms 204 KB Output is correct
9 Correct 19 ms 324 KB Output is correct
10 Correct 21 ms 320 KB Output is correct
11 Correct 19 ms 324 KB Output is correct
12 Correct 22 ms 204 KB Output is correct
13 Correct 19 ms 204 KB Output is correct
14 Correct 18 ms 316 KB Output is correct
15 Correct 19 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 6 ms 204 KB Output is correct
5 Correct 13 ms 324 KB Output is correct
6 Correct 18 ms 204 KB Output is correct
7 Correct 20 ms 204 KB Output is correct
8 Correct 19 ms 204 KB Output is correct
9 Correct 19 ms 324 KB Output is correct
10 Correct 21 ms 320 KB Output is correct
11 Correct 19 ms 324 KB Output is correct
12 Correct 22 ms 204 KB Output is correct
13 Correct 19 ms 204 KB Output is correct
14 Correct 18 ms 316 KB Output is correct
15 Correct 19 ms 320 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 7 ms 316 KB Output is correct
20 Correct 13 ms 316 KB Output is correct
21 Correct 19 ms 204 KB Output is correct
22 Correct 21 ms 316 KB Output is correct
23 Correct 19 ms 324 KB Output is correct
24 Correct 23 ms 316 KB Output is correct
25 Correct 19 ms 316 KB Output is correct
26 Correct 20 ms 324 KB Output is correct
27 Correct 23 ms 316 KB Output is correct
28 Correct 20 ms 320 KB Output is correct
29 Correct 19 ms 316 KB Output is correct
30 Correct 20 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 6 ms 204 KB Output is correct
5 Correct 13 ms 324 KB Output is correct
6 Correct 18 ms 204 KB Output is correct
7 Correct 20 ms 204 KB Output is correct
8 Correct 19 ms 204 KB Output is correct
9 Correct 19 ms 324 KB Output is correct
10 Correct 21 ms 320 KB Output is correct
11 Correct 19 ms 324 KB Output is correct
12 Correct 22 ms 204 KB Output is correct
13 Correct 19 ms 204 KB Output is correct
14 Correct 18 ms 316 KB Output is correct
15 Correct 19 ms 320 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 7 ms 316 KB Output is correct
20 Correct 13 ms 316 KB Output is correct
21 Correct 19 ms 204 KB Output is correct
22 Correct 21 ms 316 KB Output is correct
23 Correct 19 ms 324 KB Output is correct
24 Correct 23 ms 316 KB Output is correct
25 Correct 19 ms 316 KB Output is correct
26 Correct 20 ms 324 KB Output is correct
27 Correct 23 ms 316 KB Output is correct
28 Correct 20 ms 320 KB Output is correct
29 Correct 19 ms 316 KB Output is correct
30 Correct 20 ms 320 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 4 ms 332 KB Output is correct
38 Correct 5 ms 332 KB Output is correct
39 Correct 8 ms 380 KB Output is correct
40 Correct 16 ms 372 KB Output is correct
41 Correct 22 ms 372 KB Output is correct
42 Correct 25 ms 332 KB Output is correct
43 Correct 24 ms 352 KB Output is correct
44 Correct 27 ms 372 KB Output is correct
45 Correct 21 ms 332 KB Output is correct
46 Correct 22 ms 376 KB Output is correct
47 Correct 22 ms 372 KB Output is correct
48 Correct 22 ms 332 KB Output is correct
49 Correct 23 ms 332 KB Output is correct
50 Correct 21 ms 332 KB Output is correct
51 Correct 22 ms 368 KB Output is correct
52 Correct 32 ms 332 KB Output is correct
53 Correct 24 ms 332 KB Output is correct
54 Correct 21 ms 332 KB Output is correct
55 Correct 22 ms 332 KB Output is correct
56 Correct 24 ms 364 KB Output is correct
57 Correct 23 ms 348 KB Output is correct
58 Correct 21 ms 332 KB Output is correct
59 Correct 22 ms 372 KB Output is correct
60 Correct 21 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 6 ms 204 KB Output is correct
15 Correct 13 ms 324 KB Output is correct
16 Correct 18 ms 204 KB Output is correct
17 Correct 20 ms 204 KB Output is correct
18 Correct 19 ms 204 KB Output is correct
19 Correct 19 ms 324 KB Output is correct
20 Correct 21 ms 320 KB Output is correct
21 Correct 19 ms 324 KB Output is correct
22 Correct 22 ms 204 KB Output is correct
23 Correct 19 ms 204 KB Output is correct
24 Correct 18 ms 316 KB Output is correct
25 Correct 19 ms 320 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 7 ms 316 KB Output is correct
30 Correct 13 ms 316 KB Output is correct
31 Correct 19 ms 204 KB Output is correct
32 Correct 21 ms 316 KB Output is correct
33 Correct 19 ms 324 KB Output is correct
34 Correct 23 ms 316 KB Output is correct
35 Correct 19 ms 316 KB Output is correct
36 Correct 20 ms 324 KB Output is correct
37 Correct 23 ms 316 KB Output is correct
38 Correct 20 ms 320 KB Output is correct
39 Correct 19 ms 316 KB Output is correct
40 Correct 20 ms 320 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 4 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 8 ms 380 KB Output is correct
50 Correct 16 ms 372 KB Output is correct
51 Correct 22 ms 372 KB Output is correct
52 Correct 25 ms 332 KB Output is correct
53 Correct 24 ms 352 KB Output is correct
54 Correct 27 ms 372 KB Output is correct
55 Correct 21 ms 332 KB Output is correct
56 Correct 22 ms 376 KB Output is correct
57 Correct 22 ms 372 KB Output is correct
58 Correct 22 ms 332 KB Output is correct
59 Correct 23 ms 332 KB Output is correct
60 Correct 21 ms 332 KB Output is correct
61 Correct 22 ms 368 KB Output is correct
62 Correct 32 ms 332 KB Output is correct
63 Correct 24 ms 332 KB Output is correct
64 Correct 21 ms 332 KB Output is correct
65 Correct 22 ms 332 KB Output is correct
66 Correct 24 ms 364 KB Output is correct
67 Correct 23 ms 348 KB Output is correct
68 Correct 21 ms 332 KB Output is correct
69 Correct 22 ms 372 KB Output is correct
70 Correct 21 ms 368 KB Output is correct
71 Correct 5 ms 332 KB Output is correct
72 Correct 4 ms 332 KB Output is correct
73 Correct 5 ms 332 KB Output is correct
74 Correct 5 ms 332 KB Output is correct
75 Correct 6 ms 332 KB Output is correct
76 Correct 9 ms 460 KB Output is correct
77 Correct 10 ms 460 KB Output is correct
78 Correct 10 ms 568 KB Output is correct
79 Correct 9 ms 588 KB Output is correct
80 Correct 9 ms 588 KB Output is correct
81 Correct 20 ms 816 KB Output is correct
82 Correct 21 ms 836 KB Output is correct
83 Correct 23 ms 812 KB Output is correct
84 Correct 21 ms 808 KB Output is correct
85 Correct 20 ms 808 KB Output is correct
86 Correct 24 ms 1344 KB Output is correct
87 Correct 25 ms 1232 KB Output is correct
88 Correct 25 ms 1284 KB Output is correct
89 Correct 26 ms 1344 KB Output is correct
90 Correct 24 ms 1252 KB Output is correct
91 Correct 55 ms 5896 KB Output is correct
92 Correct 58 ms 5936 KB Output is correct
93 Correct 61 ms 5908 KB Output is correct
94 Correct 57 ms 5876 KB Output is correct
95 Correct 56 ms 5856 KB Output is correct
96 Correct 84 ms 11636 KB Output is correct
97 Correct 93 ms 11740 KB Output is correct
98 Correct 103 ms 11744 KB Output is correct
99 Correct 94 ms 11772 KB Output is correct
100 Correct 91 ms 11796 KB Output is correct
101 Correct 95 ms 11808 KB Output is correct
102 Correct 107 ms 11820 KB Output is correct
103 Correct 103 ms 11760 KB Output is correct
104 Correct 110 ms 11780 KB Output is correct
105 Correct 109 ms 11824 KB Output is correct
106 Correct 110 ms 13952 KB Output is correct
107 Correct 99 ms 14124 KB Output is correct
108 Correct 97 ms 13980 KB Output is correct
109 Correct 95 ms 13876 KB Output is correct
110 Correct 108 ms 13960 KB Output is correct
111 Correct 92 ms 13908 KB Output is correct
112 Correct 91 ms 13984 KB Output is correct
113 Correct 101 ms 13916 KB Output is correct
114 Correct 101 ms 13844 KB Output is correct
115 Correct 94 ms 13916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 6 ms 204 KB Output is correct
15 Correct 13 ms 324 KB Output is correct
16 Correct 18 ms 204 KB Output is correct
17 Correct 20 ms 204 KB Output is correct
18 Correct 19 ms 204 KB Output is correct
19 Correct 19 ms 324 KB Output is correct
20 Correct 21 ms 320 KB Output is correct
21 Correct 19 ms 324 KB Output is correct
22 Correct 22 ms 204 KB Output is correct
23 Correct 19 ms 204 KB Output is correct
24 Correct 18 ms 316 KB Output is correct
25 Correct 19 ms 320 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 7 ms 316 KB Output is correct
30 Correct 13 ms 316 KB Output is correct
31 Correct 19 ms 204 KB Output is correct
32 Correct 21 ms 316 KB Output is correct
33 Correct 19 ms 324 KB Output is correct
34 Correct 23 ms 316 KB Output is correct
35 Correct 19 ms 316 KB Output is correct
36 Correct 20 ms 324 KB Output is correct
37 Correct 23 ms 316 KB Output is correct
38 Correct 20 ms 320 KB Output is correct
39 Correct 19 ms 316 KB Output is correct
40 Correct 20 ms 320 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 4 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 8 ms 380 KB Output is correct
50 Correct 16 ms 372 KB Output is correct
51 Correct 22 ms 372 KB Output is correct
52 Correct 25 ms 332 KB Output is correct
53 Correct 24 ms 352 KB Output is correct
54 Correct 27 ms 372 KB Output is correct
55 Correct 21 ms 332 KB Output is correct
56 Correct 22 ms 376 KB Output is correct
57 Correct 22 ms 372 KB Output is correct
58 Correct 22 ms 332 KB Output is correct
59 Correct 23 ms 332 KB Output is correct
60 Correct 21 ms 332 KB Output is correct
61 Correct 22 ms 368 KB Output is correct
62 Correct 32 ms 332 KB Output is correct
63 Correct 24 ms 332 KB Output is correct
64 Correct 21 ms 332 KB Output is correct
65 Correct 22 ms 332 KB Output is correct
66 Correct 24 ms 364 KB Output is correct
67 Correct 23 ms 348 KB Output is correct
68 Correct 21 ms 332 KB Output is correct
69 Correct 22 ms 372 KB Output is correct
70 Correct 21 ms 368 KB Output is correct
71 Correct 5 ms 332 KB Output is correct
72 Correct 4 ms 332 KB Output is correct
73 Correct 5 ms 332 KB Output is correct
74 Correct 5 ms 332 KB Output is correct
75 Correct 6 ms 332 KB Output is correct
76 Correct 9 ms 460 KB Output is correct
77 Correct 10 ms 460 KB Output is correct
78 Correct 10 ms 568 KB Output is correct
79 Correct 9 ms 588 KB Output is correct
80 Correct 9 ms 588 KB Output is correct
81 Correct 20 ms 816 KB Output is correct
82 Correct 21 ms 836 KB Output is correct
83 Correct 23 ms 812 KB Output is correct
84 Correct 21 ms 808 KB Output is correct
85 Correct 20 ms 808 KB Output is correct
86 Correct 24 ms 1344 KB Output is correct
87 Correct 25 ms 1232 KB Output is correct
88 Correct 25 ms 1284 KB Output is correct
89 Correct 26 ms 1344 KB Output is correct
90 Correct 24 ms 1252 KB Output is correct
91 Correct 55 ms 5896 KB Output is correct
92 Correct 58 ms 5936 KB Output is correct
93 Correct 61 ms 5908 KB Output is correct
94 Correct 57 ms 5876 KB Output is correct
95 Correct 56 ms 5856 KB Output is correct
96 Correct 84 ms 11636 KB Output is correct
97 Correct 93 ms 11740 KB Output is correct
98 Correct 103 ms 11744 KB Output is correct
99 Correct 94 ms 11772 KB Output is correct
100 Correct 91 ms 11796 KB Output is correct
101 Correct 95 ms 11808 KB Output is correct
102 Correct 107 ms 11820 KB Output is correct
103 Correct 103 ms 11760 KB Output is correct
104 Correct 110 ms 11780 KB Output is correct
105 Correct 109 ms 11824 KB Output is correct
106 Correct 110 ms 13952 KB Output is correct
107 Correct 99 ms 14124 KB Output is correct
108 Correct 97 ms 13980 KB Output is correct
109 Correct 95 ms 13876 KB Output is correct
110 Correct 108 ms 13960 KB Output is correct
111 Correct 92 ms 13908 KB Output is correct
112 Correct 91 ms 13984 KB Output is correct
113 Correct 101 ms 13916 KB Output is correct
114 Correct 101 ms 13844 KB Output is correct
115 Correct 94 ms 13916 KB Output is correct
116 Incorrect 1 ms 204 KB Output isn't correct
117 Halted 0 ms 0 KB -