Submission #697515

# Submission time Handle Problem Language Result Execution time Memory
697515 2023-02-10T07:35:53 Z piOOE Diversity (CEOI21_diversity) C++17
64 / 100
107 ms 5584 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

    vector<int> a(n);

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

    vector<int> yy = a;
    sort(yy.begin(), yy.end());
    yy.resize(unique(yy.begin(), yy.end()) - yy.begin());

    for (int &x : a) {
        x = lower_bound(yy.begin(), yy.end(), x) - yy.begin();
    }

    const int m = yy.size();

    int L, R;
    cin >> L >> R;

    assert(q == 1 && L == 1 && R == n);

    vector<int> cnt(m);

    for (int x : a) {
        cnt[x] += 1;
    }

    ll ans = 0;

    for (int x : cnt) {
        ans += 1LL * x * (x + 1) / 2 + 1LL * x * (n - x);
    }

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

    int l = 0, r = 0;

    for (int x : cnt) {
        if (l < r) {
            ans += 1LL * l * (n - x - l);
            l += x;
        } else {
            ans += 1LL * r * (n - x - r);
            r += x;
        }
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1228 KB Output is correct
5 Correct 18 ms 2260 KB Output is correct
6 Correct 31 ms 3400 KB Output is correct
7 Correct 26 ms 3256 KB Output is correct
8 Correct 32 ms 3288 KB Output is correct
9 Correct 30 ms 3288 KB Output is correct
10 Correct 28 ms 3332 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3276 KB Output is correct
13 Correct 29 ms 3280 KB Output is correct
14 Correct 28 ms 3280 KB Output is correct
15 Correct 29 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1228 KB Output is correct
5 Correct 18 ms 2260 KB Output is correct
6 Correct 31 ms 3400 KB Output is correct
7 Correct 26 ms 3256 KB Output is correct
8 Correct 32 ms 3288 KB Output is correct
9 Correct 30 ms 3288 KB Output is correct
10 Correct 28 ms 3332 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3276 KB Output is correct
13 Correct 29 ms 3280 KB Output is correct
14 Correct 28 ms 3280 KB Output is correct
15 Correct 29 ms 3284 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 428 KB Output is correct
19 Correct 12 ms 1364 KB Output is correct
20 Correct 21 ms 2380 KB Output is correct
21 Correct 32 ms 3392 KB Output is correct
22 Correct 32 ms 3444 KB Output is correct
23 Correct 33 ms 3432 KB Output is correct
24 Correct 32 ms 3412 KB Output is correct
25 Correct 32 ms 3408 KB Output is correct
26 Correct 35 ms 3404 KB Output is correct
27 Correct 33 ms 3420 KB Output is correct
28 Correct 32 ms 3284 KB Output is correct
29 Correct 31 ms 3280 KB Output is correct
30 Correct 37 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1228 KB Output is correct
5 Correct 18 ms 2260 KB Output is correct
6 Correct 31 ms 3400 KB Output is correct
7 Correct 26 ms 3256 KB Output is correct
8 Correct 32 ms 3288 KB Output is correct
9 Correct 30 ms 3288 KB Output is correct
10 Correct 28 ms 3332 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3276 KB Output is correct
13 Correct 29 ms 3280 KB Output is correct
14 Correct 28 ms 3280 KB Output is correct
15 Correct 29 ms 3284 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 428 KB Output is correct
19 Correct 12 ms 1364 KB Output is correct
20 Correct 21 ms 2380 KB Output is correct
21 Correct 32 ms 3392 KB Output is correct
22 Correct 32 ms 3444 KB Output is correct
23 Correct 33 ms 3432 KB Output is correct
24 Correct 32 ms 3412 KB Output is correct
25 Correct 32 ms 3408 KB Output is correct
26 Correct 35 ms 3404 KB Output is correct
27 Correct 33 ms 3420 KB Output is correct
28 Correct 32 ms 3284 KB Output is correct
29 Correct 31 ms 3280 KB Output is correct
30 Correct 37 ms 3404 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 10 ms 896 KB Output is correct
38 Correct 10 ms 920 KB Output is correct
39 Correct 18 ms 1492 KB Output is correct
40 Correct 41 ms 2628 KB Output is correct
41 Correct 52 ms 3912 KB Output is correct
42 Correct 50 ms 3808 KB Output is correct
43 Correct 51 ms 3780 KB Output is correct
44 Correct 50 ms 3784 KB Output is correct
45 Correct 53 ms 3800 KB Output is correct
46 Correct 51 ms 3900 KB Output is correct
47 Correct 51 ms 3784 KB Output is correct
48 Correct 50 ms 3784 KB Output is correct
49 Correct 52 ms 3788 KB Output is correct
50 Correct 51 ms 3800 KB Output is correct
51 Correct 51 ms 3792 KB Output is correct
52 Correct 53 ms 3792 KB Output is correct
53 Correct 51 ms 3788 KB Output is correct
54 Correct 51 ms 3796 KB Output is correct
55 Correct 53 ms 3808 KB Output is correct
56 Correct 52 ms 3776 KB Output is correct
57 Correct 51 ms 3796 KB Output is correct
58 Correct 49 ms 3796 KB Output is correct
59 Correct 50 ms 3796 KB Output is correct
60 Correct 52 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 1228 KB Output is correct
15 Correct 18 ms 2260 KB Output is correct
16 Correct 31 ms 3400 KB Output is correct
17 Correct 26 ms 3256 KB Output is correct
18 Correct 32 ms 3288 KB Output is correct
19 Correct 30 ms 3288 KB Output is correct
20 Correct 28 ms 3332 KB Output is correct
21 Correct 28 ms 3276 KB Output is correct
22 Correct 30 ms 3276 KB Output is correct
23 Correct 29 ms 3280 KB Output is correct
24 Correct 28 ms 3280 KB Output is correct
25 Correct 29 ms 3284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 428 KB Output is correct
29 Correct 12 ms 1364 KB Output is correct
30 Correct 21 ms 2380 KB Output is correct
31 Correct 32 ms 3392 KB Output is correct
32 Correct 32 ms 3444 KB Output is correct
33 Correct 33 ms 3432 KB Output is correct
34 Correct 32 ms 3412 KB Output is correct
35 Correct 32 ms 3408 KB Output is correct
36 Correct 35 ms 3404 KB Output is correct
37 Correct 33 ms 3420 KB Output is correct
38 Correct 32 ms 3284 KB Output is correct
39 Correct 31 ms 3280 KB Output is correct
40 Correct 37 ms 3404 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 10 ms 896 KB Output is correct
48 Correct 10 ms 920 KB Output is correct
49 Correct 18 ms 1492 KB Output is correct
50 Correct 41 ms 2628 KB Output is correct
51 Correct 52 ms 3912 KB Output is correct
52 Correct 50 ms 3808 KB Output is correct
53 Correct 51 ms 3780 KB Output is correct
54 Correct 50 ms 3784 KB Output is correct
55 Correct 53 ms 3800 KB Output is correct
56 Correct 51 ms 3900 KB Output is correct
57 Correct 51 ms 3784 KB Output is correct
58 Correct 50 ms 3784 KB Output is correct
59 Correct 52 ms 3788 KB Output is correct
60 Correct 51 ms 3800 KB Output is correct
61 Correct 51 ms 3792 KB Output is correct
62 Correct 53 ms 3792 KB Output is correct
63 Correct 51 ms 3788 KB Output is correct
64 Correct 51 ms 3796 KB Output is correct
65 Correct 53 ms 3808 KB Output is correct
66 Correct 52 ms 3776 KB Output is correct
67 Correct 51 ms 3796 KB Output is correct
68 Correct 49 ms 3796 KB Output is correct
69 Correct 50 ms 3796 KB Output is correct
70 Correct 52 ms 3916 KB Output is correct
71 Correct 10 ms 852 KB Output is correct
72 Correct 10 ms 944 KB Output is correct
73 Correct 10 ms 948 KB Output is correct
74 Correct 10 ms 852 KB Output is correct
75 Correct 10 ms 840 KB Output is correct
76 Correct 21 ms 1564 KB Output is correct
77 Correct 21 ms 1492 KB Output is correct
78 Correct 21 ms 1492 KB Output is correct
79 Correct 21 ms 1572 KB Output is correct
80 Correct 20 ms 1492 KB Output is correct
81 Correct 42 ms 2880 KB Output is correct
82 Correct 42 ms 2884 KB Output is correct
83 Correct 42 ms 2764 KB Output is correct
84 Correct 49 ms 2772 KB Output is correct
85 Correct 42 ms 2852 KB Output is correct
86 Correct 49 ms 2948 KB Output is correct
87 Correct 46 ms 2948 KB Output is correct
88 Correct 48 ms 2948 KB Output is correct
89 Correct 48 ms 2964 KB Output is correct
90 Correct 46 ms 3020 KB Output is correct
91 Correct 79 ms 4680 KB Output is correct
92 Correct 80 ms 4812 KB Output is correct
93 Correct 82 ms 4772 KB Output is correct
94 Correct 85 ms 4772 KB Output is correct
95 Correct 80 ms 4680 KB Output is correct
96 Correct 88 ms 5320 KB Output is correct
97 Correct 91 ms 5320 KB Output is correct
98 Correct 89 ms 5312 KB Output is correct
99 Correct 93 ms 5324 KB Output is correct
100 Correct 89 ms 5296 KB Output is correct
101 Correct 88 ms 5316 KB Output is correct
102 Correct 92 ms 5320 KB Output is correct
103 Correct 107 ms 5296 KB Output is correct
104 Correct 95 ms 5316 KB Output is correct
105 Correct 89 ms 5324 KB Output is correct
106 Correct 94 ms 5452 KB Output is correct
107 Correct 90 ms 5476 KB Output is correct
108 Correct 92 ms 5480 KB Output is correct
109 Correct 104 ms 5484 KB Output is correct
110 Correct 92 ms 5476 KB Output is correct
111 Correct 92 ms 5460 KB Output is correct
112 Correct 93 ms 5584 KB Output is correct
113 Correct 91 ms 5480 KB Output is correct
114 Correct 92 ms 5476 KB Output is correct
115 Correct 96 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 1228 KB Output is correct
15 Correct 18 ms 2260 KB Output is correct
16 Correct 31 ms 3400 KB Output is correct
17 Correct 26 ms 3256 KB Output is correct
18 Correct 32 ms 3288 KB Output is correct
19 Correct 30 ms 3288 KB Output is correct
20 Correct 28 ms 3332 KB Output is correct
21 Correct 28 ms 3276 KB Output is correct
22 Correct 30 ms 3276 KB Output is correct
23 Correct 29 ms 3280 KB Output is correct
24 Correct 28 ms 3280 KB Output is correct
25 Correct 29 ms 3284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 428 KB Output is correct
29 Correct 12 ms 1364 KB Output is correct
30 Correct 21 ms 2380 KB Output is correct
31 Correct 32 ms 3392 KB Output is correct
32 Correct 32 ms 3444 KB Output is correct
33 Correct 33 ms 3432 KB Output is correct
34 Correct 32 ms 3412 KB Output is correct
35 Correct 32 ms 3408 KB Output is correct
36 Correct 35 ms 3404 KB Output is correct
37 Correct 33 ms 3420 KB Output is correct
38 Correct 32 ms 3284 KB Output is correct
39 Correct 31 ms 3280 KB Output is correct
40 Correct 37 ms 3404 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 10 ms 896 KB Output is correct
48 Correct 10 ms 920 KB Output is correct
49 Correct 18 ms 1492 KB Output is correct
50 Correct 41 ms 2628 KB Output is correct
51 Correct 52 ms 3912 KB Output is correct
52 Correct 50 ms 3808 KB Output is correct
53 Correct 51 ms 3780 KB Output is correct
54 Correct 50 ms 3784 KB Output is correct
55 Correct 53 ms 3800 KB Output is correct
56 Correct 51 ms 3900 KB Output is correct
57 Correct 51 ms 3784 KB Output is correct
58 Correct 50 ms 3784 KB Output is correct
59 Correct 52 ms 3788 KB Output is correct
60 Correct 51 ms 3800 KB Output is correct
61 Correct 51 ms 3792 KB Output is correct
62 Correct 53 ms 3792 KB Output is correct
63 Correct 51 ms 3788 KB Output is correct
64 Correct 51 ms 3796 KB Output is correct
65 Correct 53 ms 3808 KB Output is correct
66 Correct 52 ms 3776 KB Output is correct
67 Correct 51 ms 3796 KB Output is correct
68 Correct 49 ms 3796 KB Output is correct
69 Correct 50 ms 3796 KB Output is correct
70 Correct 52 ms 3916 KB Output is correct
71 Correct 10 ms 852 KB Output is correct
72 Correct 10 ms 944 KB Output is correct
73 Correct 10 ms 948 KB Output is correct
74 Correct 10 ms 852 KB Output is correct
75 Correct 10 ms 840 KB Output is correct
76 Correct 21 ms 1564 KB Output is correct
77 Correct 21 ms 1492 KB Output is correct
78 Correct 21 ms 1492 KB Output is correct
79 Correct 21 ms 1572 KB Output is correct
80 Correct 20 ms 1492 KB Output is correct
81 Correct 42 ms 2880 KB Output is correct
82 Correct 42 ms 2884 KB Output is correct
83 Correct 42 ms 2764 KB Output is correct
84 Correct 49 ms 2772 KB Output is correct
85 Correct 42 ms 2852 KB Output is correct
86 Correct 49 ms 2948 KB Output is correct
87 Correct 46 ms 2948 KB Output is correct
88 Correct 48 ms 2948 KB Output is correct
89 Correct 48 ms 2964 KB Output is correct
90 Correct 46 ms 3020 KB Output is correct
91 Correct 79 ms 4680 KB Output is correct
92 Correct 80 ms 4812 KB Output is correct
93 Correct 82 ms 4772 KB Output is correct
94 Correct 85 ms 4772 KB Output is correct
95 Correct 80 ms 4680 KB Output is correct
96 Correct 88 ms 5320 KB Output is correct
97 Correct 91 ms 5320 KB Output is correct
98 Correct 89 ms 5312 KB Output is correct
99 Correct 93 ms 5324 KB Output is correct
100 Correct 89 ms 5296 KB Output is correct
101 Correct 88 ms 5316 KB Output is correct
102 Correct 92 ms 5320 KB Output is correct
103 Correct 107 ms 5296 KB Output is correct
104 Correct 95 ms 5316 KB Output is correct
105 Correct 89 ms 5324 KB Output is correct
106 Correct 94 ms 5452 KB Output is correct
107 Correct 90 ms 5476 KB Output is correct
108 Correct 92 ms 5480 KB Output is correct
109 Correct 104 ms 5484 KB Output is correct
110 Correct 92 ms 5476 KB Output is correct
111 Correct 92 ms 5460 KB Output is correct
112 Correct 93 ms 5584 KB Output is correct
113 Correct 91 ms 5480 KB Output is correct
114 Correct 92 ms 5476 KB Output is correct
115 Correct 96 ms 5480 KB Output is correct
116 Runtime error 2 ms 724 KB Execution killed with signal 6
117 Halted 0 ms 0 KB -