답안 #697517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697517 2023-02-10T07:48:44 Z piOOE Diversity (CEOI21_diversity) C++17
64 / 100
94 ms 3688 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;
    int where = 1;

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

        where ^= 1;
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1108 KB Output is correct
5 Correct 17 ms 1876 KB Output is correct
6 Correct 28 ms 2612 KB Output is correct
7 Correct 26 ms 2652 KB Output is correct
8 Correct 27 ms 2684 KB Output is correct
9 Correct 27 ms 2652 KB Output is correct
10 Correct 27 ms 2660 KB Output is correct
11 Correct 28 ms 2684 KB Output is correct
12 Correct 29 ms 2656 KB Output is correct
13 Correct 29 ms 2644 KB Output is correct
14 Correct 28 ms 2656 KB Output is correct
15 Correct 28 ms 2664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1108 KB Output is correct
5 Correct 17 ms 1876 KB Output is correct
6 Correct 28 ms 2612 KB Output is correct
7 Correct 26 ms 2652 KB Output is correct
8 Correct 27 ms 2684 KB Output is correct
9 Correct 27 ms 2652 KB Output is correct
10 Correct 27 ms 2660 KB Output is correct
11 Correct 28 ms 2684 KB Output is correct
12 Correct 29 ms 2656 KB Output is correct
13 Correct 29 ms 2644 KB Output is correct
14 Correct 28 ms 2656 KB Output is correct
15 Correct 28 ms 2664 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 10 ms 1112 KB Output is correct
20 Correct 21 ms 1888 KB Output is correct
21 Correct 30 ms 2656 KB Output is correct
22 Correct 35 ms 2660 KB Output is correct
23 Correct 32 ms 2644 KB Output is correct
24 Correct 33 ms 2656 KB Output is correct
25 Correct 33 ms 2644 KB Output is correct
26 Correct 32 ms 2656 KB Output is correct
27 Correct 32 ms 2676 KB Output is correct
28 Correct 30 ms 2644 KB Output is correct
29 Correct 33 ms 2776 KB Output is correct
30 Correct 32 ms 2656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1108 KB Output is correct
5 Correct 17 ms 1876 KB Output is correct
6 Correct 28 ms 2612 KB Output is correct
7 Correct 26 ms 2652 KB Output is correct
8 Correct 27 ms 2684 KB Output is correct
9 Correct 27 ms 2652 KB Output is correct
10 Correct 27 ms 2660 KB Output is correct
11 Correct 28 ms 2684 KB Output is correct
12 Correct 29 ms 2656 KB Output is correct
13 Correct 29 ms 2644 KB Output is correct
14 Correct 28 ms 2656 KB Output is correct
15 Correct 28 ms 2664 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 10 ms 1112 KB Output is correct
20 Correct 21 ms 1888 KB Output is correct
21 Correct 30 ms 2656 KB Output is correct
22 Correct 35 ms 2660 KB Output is correct
23 Correct 32 ms 2644 KB Output is correct
24 Correct 33 ms 2656 KB Output is correct
25 Correct 33 ms 2644 KB Output is correct
26 Correct 32 ms 2656 KB Output is correct
27 Correct 32 ms 2676 KB Output is correct
28 Correct 30 ms 2644 KB Output is correct
29 Correct 33 ms 2776 KB Output is correct
30 Correct 32 ms 2656 KB Output is correct
31 Correct 0 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 356 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 8 ms 724 KB Output is correct
38 Correct 9 ms 724 KB Output is correct
39 Correct 17 ms 1108 KB Output is correct
40 Correct 36 ms 1876 KB Output is correct
41 Correct 50 ms 2660 KB Output is correct
42 Correct 63 ms 2656 KB Output is correct
43 Correct 51 ms 2656 KB Output is correct
44 Correct 49 ms 2660 KB Output is correct
45 Correct 50 ms 2660 KB Output is correct
46 Correct 49 ms 2660 KB Output is correct
47 Correct 49 ms 2644 KB Output is correct
48 Correct 49 ms 2644 KB Output is correct
49 Correct 49 ms 2664 KB Output is correct
50 Correct 50 ms 2656 KB Output is correct
51 Correct 51 ms 2656 KB Output is correct
52 Correct 51 ms 2664 KB Output is correct
53 Correct 48 ms 2660 KB Output is correct
54 Correct 50 ms 2660 KB Output is correct
55 Correct 49 ms 2656 KB Output is correct
56 Correct 49 ms 2664 KB Output is correct
57 Correct 49 ms 2656 KB Output is correct
58 Correct 50 ms 2764 KB Output is correct
59 Correct 49 ms 2660 KB Output is correct
60 Correct 49 ms 2664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 17 ms 1876 KB Output is correct
16 Correct 28 ms 2612 KB Output is correct
17 Correct 26 ms 2652 KB Output is correct
18 Correct 27 ms 2684 KB Output is correct
19 Correct 27 ms 2652 KB Output is correct
20 Correct 27 ms 2660 KB Output is correct
21 Correct 28 ms 2684 KB Output is correct
22 Correct 29 ms 2656 KB Output is correct
23 Correct 29 ms 2644 KB Output is correct
24 Correct 28 ms 2656 KB Output is correct
25 Correct 28 ms 2664 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 10 ms 1112 KB Output is correct
30 Correct 21 ms 1888 KB Output is correct
31 Correct 30 ms 2656 KB Output is correct
32 Correct 35 ms 2660 KB Output is correct
33 Correct 32 ms 2644 KB Output is correct
34 Correct 33 ms 2656 KB Output is correct
35 Correct 33 ms 2644 KB Output is correct
36 Correct 32 ms 2656 KB Output is correct
37 Correct 32 ms 2676 KB Output is correct
38 Correct 30 ms 2644 KB Output is correct
39 Correct 33 ms 2776 KB Output is correct
40 Correct 32 ms 2656 KB Output is correct
41 Correct 0 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 356 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 8 ms 724 KB Output is correct
48 Correct 9 ms 724 KB Output is correct
49 Correct 17 ms 1108 KB Output is correct
50 Correct 36 ms 1876 KB Output is correct
51 Correct 50 ms 2660 KB Output is correct
52 Correct 63 ms 2656 KB Output is correct
53 Correct 51 ms 2656 KB Output is correct
54 Correct 49 ms 2660 KB Output is correct
55 Correct 50 ms 2660 KB Output is correct
56 Correct 49 ms 2660 KB Output is correct
57 Correct 49 ms 2644 KB Output is correct
58 Correct 49 ms 2644 KB Output is correct
59 Correct 49 ms 2664 KB Output is correct
60 Correct 50 ms 2656 KB Output is correct
61 Correct 51 ms 2656 KB Output is correct
62 Correct 51 ms 2664 KB Output is correct
63 Correct 48 ms 2660 KB Output is correct
64 Correct 50 ms 2660 KB Output is correct
65 Correct 49 ms 2656 KB Output is correct
66 Correct 49 ms 2664 KB Output is correct
67 Correct 49 ms 2656 KB Output is correct
68 Correct 50 ms 2764 KB Output is correct
69 Correct 49 ms 2660 KB Output is correct
70 Correct 49 ms 2664 KB Output is correct
71 Correct 9 ms 724 KB Output is correct
72 Correct 10 ms 724 KB Output is correct
73 Correct 10 ms 724 KB Output is correct
74 Correct 10 ms 720 KB Output is correct
75 Correct 13 ms 724 KB Output is correct
76 Correct 20 ms 1108 KB Output is correct
77 Correct 21 ms 1120 KB Output is correct
78 Correct 20 ms 1112 KB Output is correct
79 Correct 22 ms 1136 KB Output is correct
80 Correct 22 ms 1112 KB Output is correct
81 Correct 41 ms 1884 KB Output is correct
82 Correct 41 ms 1896 KB Output is correct
83 Correct 40 ms 1900 KB Output is correct
84 Correct 40 ms 1900 KB Output is correct
85 Correct 44 ms 1896 KB Output is correct
86 Correct 47 ms 1892 KB Output is correct
87 Correct 47 ms 1884 KB Output is correct
88 Correct 48 ms 1888 KB Output is correct
89 Correct 54 ms 1876 KB Output is correct
90 Correct 46 ms 1884 KB Output is correct
91 Correct 79 ms 3044 KB Output is correct
92 Correct 79 ms 3044 KB Output is correct
93 Correct 83 ms 3048 KB Output is correct
94 Correct 84 ms 3020 KB Output is correct
95 Correct 79 ms 3048 KB Output is correct
96 Correct 89 ms 3428 KB Output is correct
97 Correct 87 ms 3416 KB Output is correct
98 Correct 89 ms 3432 KB Output is correct
99 Correct 88 ms 3424 KB Output is correct
100 Correct 87 ms 3424 KB Output is correct
101 Correct 87 ms 3404 KB Output is correct
102 Correct 89 ms 3428 KB Output is correct
103 Correct 89 ms 3412 KB Output is correct
104 Correct 90 ms 3432 KB Output is correct
105 Correct 93 ms 3548 KB Output is correct
106 Correct 92 ms 3688 KB Output is correct
107 Correct 91 ms 3568 KB Output is correct
108 Correct 94 ms 3556 KB Output is correct
109 Correct 92 ms 3552 KB Output is correct
110 Correct 90 ms 3556 KB Output is correct
111 Correct 91 ms 3552 KB Output is correct
112 Correct 89 ms 3560 KB Output is correct
113 Correct 88 ms 3556 KB Output is correct
114 Correct 88 ms 3552 KB Output is correct
115 Correct 89 ms 3560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 17 ms 1876 KB Output is correct
16 Correct 28 ms 2612 KB Output is correct
17 Correct 26 ms 2652 KB Output is correct
18 Correct 27 ms 2684 KB Output is correct
19 Correct 27 ms 2652 KB Output is correct
20 Correct 27 ms 2660 KB Output is correct
21 Correct 28 ms 2684 KB Output is correct
22 Correct 29 ms 2656 KB Output is correct
23 Correct 29 ms 2644 KB Output is correct
24 Correct 28 ms 2656 KB Output is correct
25 Correct 28 ms 2664 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 10 ms 1112 KB Output is correct
30 Correct 21 ms 1888 KB Output is correct
31 Correct 30 ms 2656 KB Output is correct
32 Correct 35 ms 2660 KB Output is correct
33 Correct 32 ms 2644 KB Output is correct
34 Correct 33 ms 2656 KB Output is correct
35 Correct 33 ms 2644 KB Output is correct
36 Correct 32 ms 2656 KB Output is correct
37 Correct 32 ms 2676 KB Output is correct
38 Correct 30 ms 2644 KB Output is correct
39 Correct 33 ms 2776 KB Output is correct
40 Correct 32 ms 2656 KB Output is correct
41 Correct 0 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 356 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 8 ms 724 KB Output is correct
48 Correct 9 ms 724 KB Output is correct
49 Correct 17 ms 1108 KB Output is correct
50 Correct 36 ms 1876 KB Output is correct
51 Correct 50 ms 2660 KB Output is correct
52 Correct 63 ms 2656 KB Output is correct
53 Correct 51 ms 2656 KB Output is correct
54 Correct 49 ms 2660 KB Output is correct
55 Correct 50 ms 2660 KB Output is correct
56 Correct 49 ms 2660 KB Output is correct
57 Correct 49 ms 2644 KB Output is correct
58 Correct 49 ms 2644 KB Output is correct
59 Correct 49 ms 2664 KB Output is correct
60 Correct 50 ms 2656 KB Output is correct
61 Correct 51 ms 2656 KB Output is correct
62 Correct 51 ms 2664 KB Output is correct
63 Correct 48 ms 2660 KB Output is correct
64 Correct 50 ms 2660 KB Output is correct
65 Correct 49 ms 2656 KB Output is correct
66 Correct 49 ms 2664 KB Output is correct
67 Correct 49 ms 2656 KB Output is correct
68 Correct 50 ms 2764 KB Output is correct
69 Correct 49 ms 2660 KB Output is correct
70 Correct 49 ms 2664 KB Output is correct
71 Correct 9 ms 724 KB Output is correct
72 Correct 10 ms 724 KB Output is correct
73 Correct 10 ms 724 KB Output is correct
74 Correct 10 ms 720 KB Output is correct
75 Correct 13 ms 724 KB Output is correct
76 Correct 20 ms 1108 KB Output is correct
77 Correct 21 ms 1120 KB Output is correct
78 Correct 20 ms 1112 KB Output is correct
79 Correct 22 ms 1136 KB Output is correct
80 Correct 22 ms 1112 KB Output is correct
81 Correct 41 ms 1884 KB Output is correct
82 Correct 41 ms 1896 KB Output is correct
83 Correct 40 ms 1900 KB Output is correct
84 Correct 40 ms 1900 KB Output is correct
85 Correct 44 ms 1896 KB Output is correct
86 Correct 47 ms 1892 KB Output is correct
87 Correct 47 ms 1884 KB Output is correct
88 Correct 48 ms 1888 KB Output is correct
89 Correct 54 ms 1876 KB Output is correct
90 Correct 46 ms 1884 KB Output is correct
91 Correct 79 ms 3044 KB Output is correct
92 Correct 79 ms 3044 KB Output is correct
93 Correct 83 ms 3048 KB Output is correct
94 Correct 84 ms 3020 KB Output is correct
95 Correct 79 ms 3048 KB Output is correct
96 Correct 89 ms 3428 KB Output is correct
97 Correct 87 ms 3416 KB Output is correct
98 Correct 89 ms 3432 KB Output is correct
99 Correct 88 ms 3424 KB Output is correct
100 Correct 87 ms 3424 KB Output is correct
101 Correct 87 ms 3404 KB Output is correct
102 Correct 89 ms 3428 KB Output is correct
103 Correct 89 ms 3412 KB Output is correct
104 Correct 90 ms 3432 KB Output is correct
105 Correct 93 ms 3548 KB Output is correct
106 Correct 92 ms 3688 KB Output is correct
107 Correct 91 ms 3568 KB Output is correct
108 Correct 94 ms 3556 KB Output is correct
109 Correct 92 ms 3552 KB Output is correct
110 Correct 90 ms 3556 KB Output is correct
111 Correct 91 ms 3552 KB Output is correct
112 Correct 89 ms 3560 KB Output is correct
113 Correct 88 ms 3556 KB Output is correct
114 Correct 88 ms 3552 KB Output is correct
115 Correct 89 ms 3560 KB Output is correct
116 Runtime error 2 ms 596 KB Execution killed with signal 6
117 Halted 0 ms 0 KB -