Submission #520458

# Submission time Handle Problem Language Result Execution time Memory
520458 2022-01-30T04:42:38 Z KoD Diversity (CEOI21_diversity) C++17
64 / 100
37 ms 2668 KB
#include <bits/stdc++.h>
 
using std::vector;
using std::array;
using std::pair;
using std::tuple;
 
using i64 = std::int64_t;

constexpr int MAX = 300000;

constexpr i64 sum_k(const int n) {
    return (i64)n * (n + 1) / 2;
}

constexpr i64 sum_k2(const int n) {
    return (i64)n * (n + 1) * (2 * n + 1) / 6;
}
 
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, Q;
    std::cin >> N >> Q;
    vector<int> count(MAX);
    for (int i = 0; i < N; ++i) {
        int x;
        std::cin >> x;
        count[x - 1] += 1;
    }
    vector<int> block(N + 1);
    for (int i = 0; i < MAX; ++i) {
        block[count[i]] += 1;
    }
    int left = 0, right = 0;
    i64 ans = sum_k(N);
    const auto add_to = [&](const i64 s, const int a, const int n) {
        ans += (n * s + sum_k(n) * a) * N;
        ans -= n * s * s + 2 * s * sum_k(n) * a + sum_k2(n) * a * a;
    };
    for (int a = 1; a <= N; ++a) {
        const int b = block[a];
        if (b == 0) {
            continue;
        }
        if (left > right) {
            std::swap(left, right);
        }
        const int need = std::min(b, (right - left + a - 1) / a);
        const int to_left = need + (b - need) / 2;
        const int to_right = b - to_left;
        add_to(left, a, to_left);
        add_to(right, a, to_right);
        left += a * to_left;
        right += a * to_right;
    }
    ans -= (i64)left * (N - left);
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 3 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 6 ms 1868 KB Output is correct
5 Correct 11 ms 2268 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 15 ms 2652 KB Output is correct
8 Correct 20 ms 2652 KB Output is correct
9 Correct 17 ms 2648 KB Output is correct
10 Correct 16 ms 2636 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 16 ms 2648 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 22 ms 2652 KB Output is correct
15 Correct 22 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 6 ms 1868 KB Output is correct
5 Correct 11 ms 2268 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 15 ms 2652 KB Output is correct
8 Correct 20 ms 2652 KB Output is correct
9 Correct 17 ms 2648 KB Output is correct
10 Correct 16 ms 2636 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 16 ms 2648 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 22 ms 2652 KB Output is correct
15 Correct 22 ms 2640 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 2 ms 1484 KB Output is correct
18 Correct 2 ms 1484 KB Output is correct
19 Correct 7 ms 1868 KB Output is correct
20 Correct 12 ms 2268 KB Output is correct
21 Correct 17 ms 2636 KB Output is correct
22 Correct 21 ms 2636 KB Output is correct
23 Correct 18 ms 2636 KB Output is correct
24 Correct 17 ms 2652 KB Output is correct
25 Correct 18 ms 2644 KB Output is correct
26 Correct 18 ms 2628 KB Output is correct
27 Correct 18 ms 2644 KB Output is correct
28 Correct 26 ms 2656 KB Output is correct
29 Correct 18 ms 2648 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 6 ms 1868 KB Output is correct
5 Correct 11 ms 2268 KB Output is correct
6 Correct 17 ms 2636 KB Output is correct
7 Correct 15 ms 2652 KB Output is correct
8 Correct 20 ms 2652 KB Output is correct
9 Correct 17 ms 2648 KB Output is correct
10 Correct 16 ms 2636 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 16 ms 2648 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 22 ms 2652 KB Output is correct
15 Correct 22 ms 2640 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 2 ms 1484 KB Output is correct
18 Correct 2 ms 1484 KB Output is correct
19 Correct 7 ms 1868 KB Output is correct
20 Correct 12 ms 2268 KB Output is correct
21 Correct 17 ms 2636 KB Output is correct
22 Correct 21 ms 2636 KB Output is correct
23 Correct 18 ms 2636 KB Output is correct
24 Correct 17 ms 2652 KB Output is correct
25 Correct 18 ms 2644 KB Output is correct
26 Correct 18 ms 2628 KB Output is correct
27 Correct 18 ms 2644 KB Output is correct
28 Correct 26 ms 2656 KB Output is correct
29 Correct 18 ms 2648 KB Output is correct
30 Correct 19 ms 2636 KB Output is correct
31 Correct 2 ms 1484 KB Output is correct
32 Correct 2 ms 1484 KB Output is correct
33 Correct 2 ms 1484 KB Output is correct
34 Correct 2 ms 1484 KB Output is correct
35 Correct 2 ms 1484 KB Output is correct
36 Correct 3 ms 1484 KB Output is correct
37 Correct 5 ms 1612 KB Output is correct
38 Correct 5 ms 1612 KB Output is correct
39 Correct 7 ms 1868 KB Output is correct
40 Correct 13 ms 2264 KB Output is correct
41 Correct 19 ms 2572 KB Output is correct
42 Correct 22 ms 2652 KB Output is correct
43 Correct 27 ms 2588 KB Output is correct
44 Correct 19 ms 2656 KB Output is correct
45 Correct 21 ms 2624 KB Output is correct
46 Correct 18 ms 2644 KB Output is correct
47 Correct 19 ms 2668 KB Output is correct
48 Correct 19 ms 2648 KB Output is correct
49 Correct 19 ms 2636 KB Output is correct
50 Correct 19 ms 2644 KB Output is correct
51 Correct 19 ms 2636 KB Output is correct
52 Correct 20 ms 2628 KB Output is correct
53 Correct 19 ms 2628 KB Output is correct
54 Correct 18 ms 2652 KB Output is correct
55 Correct 19 ms 2652 KB Output is correct
56 Correct 19 ms 2648 KB Output is correct
57 Correct 27 ms 2640 KB Output is correct
58 Correct 18 ms 2636 KB Output is correct
59 Correct 21 ms 2648 KB Output is correct
60 Correct 19 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 3 ms 1484 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 6 ms 1868 KB Output is correct
15 Correct 11 ms 2268 KB Output is correct
16 Correct 17 ms 2636 KB Output is correct
17 Correct 15 ms 2652 KB Output is correct
18 Correct 20 ms 2652 KB Output is correct
19 Correct 17 ms 2648 KB Output is correct
20 Correct 16 ms 2636 KB Output is correct
21 Correct 16 ms 2652 KB Output is correct
22 Correct 16 ms 2648 KB Output is correct
23 Correct 16 ms 2648 KB Output is correct
24 Correct 22 ms 2652 KB Output is correct
25 Correct 22 ms 2640 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 2 ms 1484 KB Output is correct
28 Correct 2 ms 1484 KB Output is correct
29 Correct 7 ms 1868 KB Output is correct
30 Correct 12 ms 2268 KB Output is correct
31 Correct 17 ms 2636 KB Output is correct
32 Correct 21 ms 2636 KB Output is correct
33 Correct 18 ms 2636 KB Output is correct
34 Correct 17 ms 2652 KB Output is correct
35 Correct 18 ms 2644 KB Output is correct
36 Correct 18 ms 2628 KB Output is correct
37 Correct 18 ms 2644 KB Output is correct
38 Correct 26 ms 2656 KB Output is correct
39 Correct 18 ms 2648 KB Output is correct
40 Correct 19 ms 2636 KB Output is correct
41 Correct 2 ms 1484 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 2 ms 1484 KB Output is correct
44 Correct 2 ms 1484 KB Output is correct
45 Correct 2 ms 1484 KB Output is correct
46 Correct 3 ms 1484 KB Output is correct
47 Correct 5 ms 1612 KB Output is correct
48 Correct 5 ms 1612 KB Output is correct
49 Correct 7 ms 1868 KB Output is correct
50 Correct 13 ms 2264 KB Output is correct
51 Correct 19 ms 2572 KB Output is correct
52 Correct 22 ms 2652 KB Output is correct
53 Correct 27 ms 2588 KB Output is correct
54 Correct 19 ms 2656 KB Output is correct
55 Correct 21 ms 2624 KB Output is correct
56 Correct 18 ms 2644 KB Output is correct
57 Correct 19 ms 2668 KB Output is correct
58 Correct 19 ms 2648 KB Output is correct
59 Correct 19 ms 2636 KB Output is correct
60 Correct 19 ms 2644 KB Output is correct
61 Correct 19 ms 2636 KB Output is correct
62 Correct 20 ms 2628 KB Output is correct
63 Correct 19 ms 2628 KB Output is correct
64 Correct 18 ms 2652 KB Output is correct
65 Correct 19 ms 2652 KB Output is correct
66 Correct 19 ms 2648 KB Output is correct
67 Correct 27 ms 2640 KB Output is correct
68 Correct 18 ms 2636 KB Output is correct
69 Correct 21 ms 2648 KB Output is correct
70 Correct 19 ms 2652 KB Output is correct
71 Correct 5 ms 1612 KB Output is correct
72 Correct 6 ms 1628 KB Output is correct
73 Correct 6 ms 1628 KB Output is correct
74 Correct 6 ms 1612 KB Output is correct
75 Correct 8 ms 1612 KB Output is correct
76 Correct 10 ms 1868 KB Output is correct
77 Correct 10 ms 1876 KB Output is correct
78 Correct 8 ms 1884 KB Output is correct
79 Correct 8 ms 1868 KB Output is correct
80 Correct 8 ms 1888 KB Output is correct
81 Correct 14 ms 2264 KB Output is correct
82 Correct 14 ms 2272 KB Output is correct
83 Correct 18 ms 2252 KB Output is correct
84 Correct 16 ms 2268 KB Output is correct
85 Correct 15 ms 2288 KB Output is correct
86 Correct 16 ms 2260 KB Output is correct
87 Correct 17 ms 2284 KB Output is correct
88 Correct 16 ms 2252 KB Output is correct
89 Correct 19 ms 2268 KB Output is correct
90 Correct 17 ms 2260 KB Output is correct
91 Correct 22 ms 2652 KB Output is correct
92 Correct 23 ms 2656 KB Output is correct
93 Correct 23 ms 2656 KB Output is correct
94 Correct 24 ms 2624 KB Output is correct
95 Correct 24 ms 2648 KB Output is correct
96 Correct 26 ms 2648 KB Output is correct
97 Correct 26 ms 2640 KB Output is correct
98 Correct 25 ms 2648 KB Output is correct
99 Correct 28 ms 2648 KB Output is correct
100 Correct 28 ms 2640 KB Output is correct
101 Correct 26 ms 2636 KB Output is correct
102 Correct 28 ms 2636 KB Output is correct
103 Correct 26 ms 2640 KB Output is correct
104 Correct 27 ms 2644 KB Output is correct
105 Correct 26 ms 2640 KB Output is correct
106 Correct 26 ms 2636 KB Output is correct
107 Correct 25 ms 2636 KB Output is correct
108 Correct 28 ms 2660 KB Output is correct
109 Correct 37 ms 2636 KB Output is correct
110 Correct 29 ms 2648 KB Output is correct
111 Correct 32 ms 2636 KB Output is correct
112 Correct 26 ms 2652 KB Output is correct
113 Correct 25 ms 2640 KB Output is correct
114 Correct 26 ms 2648 KB Output is correct
115 Correct 26 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 2 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1484 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 3 ms 1484 KB Output is correct
11 Correct 2 ms 1484 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 6 ms 1868 KB Output is correct
15 Correct 11 ms 2268 KB Output is correct
16 Correct 17 ms 2636 KB Output is correct
17 Correct 15 ms 2652 KB Output is correct
18 Correct 20 ms 2652 KB Output is correct
19 Correct 17 ms 2648 KB Output is correct
20 Correct 16 ms 2636 KB Output is correct
21 Correct 16 ms 2652 KB Output is correct
22 Correct 16 ms 2648 KB Output is correct
23 Correct 16 ms 2648 KB Output is correct
24 Correct 22 ms 2652 KB Output is correct
25 Correct 22 ms 2640 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 2 ms 1484 KB Output is correct
28 Correct 2 ms 1484 KB Output is correct
29 Correct 7 ms 1868 KB Output is correct
30 Correct 12 ms 2268 KB Output is correct
31 Correct 17 ms 2636 KB Output is correct
32 Correct 21 ms 2636 KB Output is correct
33 Correct 18 ms 2636 KB Output is correct
34 Correct 17 ms 2652 KB Output is correct
35 Correct 18 ms 2644 KB Output is correct
36 Correct 18 ms 2628 KB Output is correct
37 Correct 18 ms 2644 KB Output is correct
38 Correct 26 ms 2656 KB Output is correct
39 Correct 18 ms 2648 KB Output is correct
40 Correct 19 ms 2636 KB Output is correct
41 Correct 2 ms 1484 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 2 ms 1484 KB Output is correct
44 Correct 2 ms 1484 KB Output is correct
45 Correct 2 ms 1484 KB Output is correct
46 Correct 3 ms 1484 KB Output is correct
47 Correct 5 ms 1612 KB Output is correct
48 Correct 5 ms 1612 KB Output is correct
49 Correct 7 ms 1868 KB Output is correct
50 Correct 13 ms 2264 KB Output is correct
51 Correct 19 ms 2572 KB Output is correct
52 Correct 22 ms 2652 KB Output is correct
53 Correct 27 ms 2588 KB Output is correct
54 Correct 19 ms 2656 KB Output is correct
55 Correct 21 ms 2624 KB Output is correct
56 Correct 18 ms 2644 KB Output is correct
57 Correct 19 ms 2668 KB Output is correct
58 Correct 19 ms 2648 KB Output is correct
59 Correct 19 ms 2636 KB Output is correct
60 Correct 19 ms 2644 KB Output is correct
61 Correct 19 ms 2636 KB Output is correct
62 Correct 20 ms 2628 KB Output is correct
63 Correct 19 ms 2628 KB Output is correct
64 Correct 18 ms 2652 KB Output is correct
65 Correct 19 ms 2652 KB Output is correct
66 Correct 19 ms 2648 KB Output is correct
67 Correct 27 ms 2640 KB Output is correct
68 Correct 18 ms 2636 KB Output is correct
69 Correct 21 ms 2648 KB Output is correct
70 Correct 19 ms 2652 KB Output is correct
71 Correct 5 ms 1612 KB Output is correct
72 Correct 6 ms 1628 KB Output is correct
73 Correct 6 ms 1628 KB Output is correct
74 Correct 6 ms 1612 KB Output is correct
75 Correct 8 ms 1612 KB Output is correct
76 Correct 10 ms 1868 KB Output is correct
77 Correct 10 ms 1876 KB Output is correct
78 Correct 8 ms 1884 KB Output is correct
79 Correct 8 ms 1868 KB Output is correct
80 Correct 8 ms 1888 KB Output is correct
81 Correct 14 ms 2264 KB Output is correct
82 Correct 14 ms 2272 KB Output is correct
83 Correct 18 ms 2252 KB Output is correct
84 Correct 16 ms 2268 KB Output is correct
85 Correct 15 ms 2288 KB Output is correct
86 Correct 16 ms 2260 KB Output is correct
87 Correct 17 ms 2284 KB Output is correct
88 Correct 16 ms 2252 KB Output is correct
89 Correct 19 ms 2268 KB Output is correct
90 Correct 17 ms 2260 KB Output is correct
91 Correct 22 ms 2652 KB Output is correct
92 Correct 23 ms 2656 KB Output is correct
93 Correct 23 ms 2656 KB Output is correct
94 Correct 24 ms 2624 KB Output is correct
95 Correct 24 ms 2648 KB Output is correct
96 Correct 26 ms 2648 KB Output is correct
97 Correct 26 ms 2640 KB Output is correct
98 Correct 25 ms 2648 KB Output is correct
99 Correct 28 ms 2648 KB Output is correct
100 Correct 28 ms 2640 KB Output is correct
101 Correct 26 ms 2636 KB Output is correct
102 Correct 28 ms 2636 KB Output is correct
103 Correct 26 ms 2640 KB Output is correct
104 Correct 27 ms 2644 KB Output is correct
105 Correct 26 ms 2640 KB Output is correct
106 Correct 26 ms 2636 KB Output is correct
107 Correct 25 ms 2636 KB Output is correct
108 Correct 28 ms 2660 KB Output is correct
109 Correct 37 ms 2636 KB Output is correct
110 Correct 29 ms 2648 KB Output is correct
111 Correct 32 ms 2636 KB Output is correct
112 Correct 26 ms 2652 KB Output is correct
113 Correct 25 ms 2640 KB Output is correct
114 Correct 26 ms 2648 KB Output is correct
115 Correct 26 ms 2652 KB Output is correct
116 Incorrect 2 ms 1484 KB Output isn't correct
117 Halted 0 ms 0 KB -