답안 #589832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589832 2022-07-05T10:45:46 Z alextodoran Diversity (CEOI21_diversity) C++17
64 / 100
66 ms 4572 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 300000;

int N, Q;
int A[N_MAX + 2];

ll solve (map <int, int> &mp) {
    int sum = 0, cnt = 0;
    ll sumLR = 0, sumRL = 0;
    ll X = 0, Y = 0;
    for (map <int, int> :: reverse_iterator it = mp.rbegin(); it != mp.rend(); it++) {
        int len, occ; tie(len, occ) = *it;
        for (int i = 1; i <= occ; i++) {
            if (sumLR < sumRL) {
                Y += sumRL * len + ((ll) sum * sum - X) / 2;
                X += (ll) len * len;
                sumLR += sum;
                sumRL += (ll) len * cnt;
                sum += len;
                cnt += 1;
            } else {
                Y += sumLR * len + ((ll) sum * sum - X) / 2;
                X += (ll) len * len;
                sumRL += sum;
                sumLR += (ll) len * cnt;
                sum += len;
                cnt += 1;
            }
        }
    }
    ll ret = (cnt - 1) * X + 2 * Y;
    ret += (ll) sum * (cnt - 1);
    ret /= 2;
    return ret;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    sort(A + 1, A + N + 1);

    vector <int> v;
    for (int i = 1; i <= N; i++) {
        if (A[i] == A[i - 1]) {
            v.back()++;
        } else {
            v.push_back(1);
        }
    }

    int l, r;
    cin >> l >> r;

    map <int, int> mp;
    for (int len : v) {
        mp[len]++;
    }
    cout << (ll) (int) v.size() * N * (N + 1) / 2 - solve(mp) << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 22 ms 2104 KB Output is correct
7 Correct 21 ms 2088 KB Output is correct
8 Correct 23 ms 2020 KB Output is correct
9 Correct 22 ms 2004 KB Output is correct
10 Correct 22 ms 2156 KB Output is correct
11 Correct 23 ms 2140 KB Output is correct
12 Correct 30 ms 2124 KB Output is correct
13 Correct 26 ms 2104 KB Output is correct
14 Correct 26 ms 2064 KB Output is correct
15 Correct 23 ms 2104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 22 ms 2104 KB Output is correct
7 Correct 21 ms 2088 KB Output is correct
8 Correct 23 ms 2020 KB Output is correct
9 Correct 22 ms 2004 KB Output is correct
10 Correct 22 ms 2156 KB Output is correct
11 Correct 23 ms 2140 KB Output is correct
12 Correct 30 ms 2124 KB Output is correct
13 Correct 26 ms 2104 KB Output is correct
14 Correct 26 ms 2064 KB Output is correct
15 Correct 23 ms 2104 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 9 ms 980 KB Output is correct
20 Correct 17 ms 1544 KB Output is correct
21 Correct 24 ms 2192 KB Output is correct
22 Correct 27 ms 2260 KB Output is correct
23 Correct 24 ms 2248 KB Output is correct
24 Correct 26 ms 2204 KB Output is correct
25 Correct 26 ms 2172 KB Output is correct
26 Correct 27 ms 2228 KB Output is correct
27 Correct 25 ms 2156 KB Output is correct
28 Correct 25 ms 2236 KB Output is correct
29 Correct 24 ms 2132 KB Output is correct
30 Correct 24 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 22 ms 2104 KB Output is correct
7 Correct 21 ms 2088 KB Output is correct
8 Correct 23 ms 2020 KB Output is correct
9 Correct 22 ms 2004 KB Output is correct
10 Correct 22 ms 2156 KB Output is correct
11 Correct 23 ms 2140 KB Output is correct
12 Correct 30 ms 2124 KB Output is correct
13 Correct 26 ms 2104 KB Output is correct
14 Correct 26 ms 2064 KB Output is correct
15 Correct 23 ms 2104 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 9 ms 980 KB Output is correct
20 Correct 17 ms 1544 KB Output is correct
21 Correct 24 ms 2192 KB Output is correct
22 Correct 27 ms 2260 KB Output is correct
23 Correct 24 ms 2248 KB Output is correct
24 Correct 26 ms 2204 KB Output is correct
25 Correct 26 ms 2172 KB Output is correct
26 Correct 27 ms 2228 KB Output is correct
27 Correct 25 ms 2156 KB Output is correct
28 Correct 25 ms 2236 KB Output is correct
29 Correct 24 ms 2132 KB Output is correct
30 Correct 24 ms 2252 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 2 ms 368 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 6 ms 724 KB Output is correct
38 Correct 6 ms 704 KB Output is correct
39 Correct 11 ms 1064 KB Output is correct
40 Correct 22 ms 1880 KB Output is correct
41 Correct 33 ms 2640 KB Output is correct
42 Correct 32 ms 2636 KB Output is correct
43 Correct 32 ms 2588 KB Output is correct
44 Correct 32 ms 2556 KB Output is correct
45 Correct 32 ms 2568 KB Output is correct
46 Correct 31 ms 2608 KB Output is correct
47 Correct 35 ms 2640 KB Output is correct
48 Correct 35 ms 2652 KB Output is correct
49 Correct 42 ms 2636 KB Output is correct
50 Correct 33 ms 2628 KB Output is correct
51 Correct 32 ms 2624 KB Output is correct
52 Correct 32 ms 2636 KB Output is correct
53 Correct 36 ms 2612 KB Output is correct
54 Correct 35 ms 2628 KB Output is correct
55 Correct 43 ms 2644 KB Output is correct
56 Correct 43 ms 2592 KB Output is correct
57 Correct 33 ms 2636 KB Output is correct
58 Correct 32 ms 2636 KB Output is correct
59 Correct 35 ms 2636 KB Output is correct
60 Correct 34 ms 2600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 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 0 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 836 KB Output is correct
15 Correct 14 ms 1492 KB Output is correct
16 Correct 22 ms 2104 KB Output is correct
17 Correct 21 ms 2088 KB Output is correct
18 Correct 23 ms 2020 KB Output is correct
19 Correct 22 ms 2004 KB Output is correct
20 Correct 22 ms 2156 KB Output is correct
21 Correct 23 ms 2140 KB Output is correct
22 Correct 30 ms 2124 KB Output is correct
23 Correct 26 ms 2104 KB Output is correct
24 Correct 26 ms 2064 KB Output is correct
25 Correct 23 ms 2104 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 9 ms 980 KB Output is correct
30 Correct 17 ms 1544 KB Output is correct
31 Correct 24 ms 2192 KB Output is correct
32 Correct 27 ms 2260 KB Output is correct
33 Correct 24 ms 2248 KB Output is correct
34 Correct 26 ms 2204 KB Output is correct
35 Correct 26 ms 2172 KB Output is correct
36 Correct 27 ms 2228 KB Output is correct
37 Correct 25 ms 2156 KB Output is correct
38 Correct 25 ms 2236 KB Output is correct
39 Correct 24 ms 2132 KB Output is correct
40 Correct 24 ms 2252 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 2 ms 368 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 336 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 6 ms 704 KB Output is correct
49 Correct 11 ms 1064 KB Output is correct
50 Correct 22 ms 1880 KB Output is correct
51 Correct 33 ms 2640 KB Output is correct
52 Correct 32 ms 2636 KB Output is correct
53 Correct 32 ms 2588 KB Output is correct
54 Correct 32 ms 2556 KB Output is correct
55 Correct 32 ms 2568 KB Output is correct
56 Correct 31 ms 2608 KB Output is correct
57 Correct 35 ms 2640 KB Output is correct
58 Correct 35 ms 2652 KB Output is correct
59 Correct 42 ms 2636 KB Output is correct
60 Correct 33 ms 2628 KB Output is correct
61 Correct 32 ms 2624 KB Output is correct
62 Correct 32 ms 2636 KB Output is correct
63 Correct 36 ms 2612 KB Output is correct
64 Correct 35 ms 2628 KB Output is correct
65 Correct 43 ms 2644 KB Output is correct
66 Correct 43 ms 2592 KB Output is correct
67 Correct 33 ms 2636 KB Output is correct
68 Correct 32 ms 2636 KB Output is correct
69 Correct 35 ms 2636 KB Output is correct
70 Correct 34 ms 2600 KB Output is correct
71 Correct 9 ms 724 KB Output is correct
72 Correct 7 ms 724 KB Output is correct
73 Correct 7 ms 724 KB Output is correct
74 Correct 7 ms 644 KB Output is correct
75 Correct 9 ms 724 KB Output is correct
76 Correct 14 ms 1236 KB Output is correct
77 Correct 14 ms 1152 KB Output is correct
78 Correct 13 ms 1192 KB Output is correct
79 Correct 14 ms 1228 KB Output is correct
80 Correct 13 ms 1188 KB Output is correct
81 Correct 30 ms 2044 KB Output is correct
82 Correct 26 ms 2132 KB Output is correct
83 Correct 27 ms 2112 KB Output is correct
84 Correct 27 ms 2072 KB Output is correct
85 Correct 27 ms 2132 KB Output is correct
86 Correct 29 ms 2252 KB Output is correct
87 Correct 28 ms 2368 KB Output is correct
88 Correct 30 ms 2252 KB Output is correct
89 Correct 30 ms 2352 KB Output is correct
90 Correct 30 ms 2288 KB Output is correct
91 Correct 56 ms 3852 KB Output is correct
92 Correct 46 ms 3852 KB Output is correct
93 Correct 45 ms 3792 KB Output is correct
94 Correct 48 ms 3848 KB Output is correct
95 Correct 55 ms 3852 KB Output is correct
96 Correct 51 ms 4528 KB Output is correct
97 Correct 57 ms 4556 KB Output is correct
98 Correct 52 ms 4452 KB Output is correct
99 Correct 49 ms 4528 KB Output is correct
100 Correct 53 ms 4528 KB Output is correct
101 Correct 51 ms 4508 KB Output is correct
102 Correct 51 ms 4524 KB Output is correct
103 Correct 66 ms 4520 KB Output is correct
104 Correct 57 ms 4508 KB Output is correct
105 Correct 63 ms 4556 KB Output is correct
106 Correct 51 ms 4572 KB Output is correct
107 Correct 51 ms 4560 KB Output is correct
108 Correct 50 ms 4556 KB Output is correct
109 Correct 50 ms 4556 KB Output is correct
110 Correct 56 ms 4484 KB Output is correct
111 Correct 48 ms 4560 KB Output is correct
112 Correct 47 ms 4464 KB Output is correct
113 Correct 49 ms 4556 KB Output is correct
114 Correct 51 ms 4556 KB Output is correct
115 Correct 65 ms 4492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 0 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 0 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 836 KB Output is correct
15 Correct 14 ms 1492 KB Output is correct
16 Correct 22 ms 2104 KB Output is correct
17 Correct 21 ms 2088 KB Output is correct
18 Correct 23 ms 2020 KB Output is correct
19 Correct 22 ms 2004 KB Output is correct
20 Correct 22 ms 2156 KB Output is correct
21 Correct 23 ms 2140 KB Output is correct
22 Correct 30 ms 2124 KB Output is correct
23 Correct 26 ms 2104 KB Output is correct
24 Correct 26 ms 2064 KB Output is correct
25 Correct 23 ms 2104 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 9 ms 980 KB Output is correct
30 Correct 17 ms 1544 KB Output is correct
31 Correct 24 ms 2192 KB Output is correct
32 Correct 27 ms 2260 KB Output is correct
33 Correct 24 ms 2248 KB Output is correct
34 Correct 26 ms 2204 KB Output is correct
35 Correct 26 ms 2172 KB Output is correct
36 Correct 27 ms 2228 KB Output is correct
37 Correct 25 ms 2156 KB Output is correct
38 Correct 25 ms 2236 KB Output is correct
39 Correct 24 ms 2132 KB Output is correct
40 Correct 24 ms 2252 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 2 ms 368 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 336 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 6 ms 704 KB Output is correct
49 Correct 11 ms 1064 KB Output is correct
50 Correct 22 ms 1880 KB Output is correct
51 Correct 33 ms 2640 KB Output is correct
52 Correct 32 ms 2636 KB Output is correct
53 Correct 32 ms 2588 KB Output is correct
54 Correct 32 ms 2556 KB Output is correct
55 Correct 32 ms 2568 KB Output is correct
56 Correct 31 ms 2608 KB Output is correct
57 Correct 35 ms 2640 KB Output is correct
58 Correct 35 ms 2652 KB Output is correct
59 Correct 42 ms 2636 KB Output is correct
60 Correct 33 ms 2628 KB Output is correct
61 Correct 32 ms 2624 KB Output is correct
62 Correct 32 ms 2636 KB Output is correct
63 Correct 36 ms 2612 KB Output is correct
64 Correct 35 ms 2628 KB Output is correct
65 Correct 43 ms 2644 KB Output is correct
66 Correct 43 ms 2592 KB Output is correct
67 Correct 33 ms 2636 KB Output is correct
68 Correct 32 ms 2636 KB Output is correct
69 Correct 35 ms 2636 KB Output is correct
70 Correct 34 ms 2600 KB Output is correct
71 Correct 9 ms 724 KB Output is correct
72 Correct 7 ms 724 KB Output is correct
73 Correct 7 ms 724 KB Output is correct
74 Correct 7 ms 644 KB Output is correct
75 Correct 9 ms 724 KB Output is correct
76 Correct 14 ms 1236 KB Output is correct
77 Correct 14 ms 1152 KB Output is correct
78 Correct 13 ms 1192 KB Output is correct
79 Correct 14 ms 1228 KB Output is correct
80 Correct 13 ms 1188 KB Output is correct
81 Correct 30 ms 2044 KB Output is correct
82 Correct 26 ms 2132 KB Output is correct
83 Correct 27 ms 2112 KB Output is correct
84 Correct 27 ms 2072 KB Output is correct
85 Correct 27 ms 2132 KB Output is correct
86 Correct 29 ms 2252 KB Output is correct
87 Correct 28 ms 2368 KB Output is correct
88 Correct 30 ms 2252 KB Output is correct
89 Correct 30 ms 2352 KB Output is correct
90 Correct 30 ms 2288 KB Output is correct
91 Correct 56 ms 3852 KB Output is correct
92 Correct 46 ms 3852 KB Output is correct
93 Correct 45 ms 3792 KB Output is correct
94 Correct 48 ms 3848 KB Output is correct
95 Correct 55 ms 3852 KB Output is correct
96 Correct 51 ms 4528 KB Output is correct
97 Correct 57 ms 4556 KB Output is correct
98 Correct 52 ms 4452 KB Output is correct
99 Correct 49 ms 4528 KB Output is correct
100 Correct 53 ms 4528 KB Output is correct
101 Correct 51 ms 4508 KB Output is correct
102 Correct 51 ms 4524 KB Output is correct
103 Correct 66 ms 4520 KB Output is correct
104 Correct 57 ms 4508 KB Output is correct
105 Correct 63 ms 4556 KB Output is correct
106 Correct 51 ms 4572 KB Output is correct
107 Correct 51 ms 4560 KB Output is correct
108 Correct 50 ms 4556 KB Output is correct
109 Correct 50 ms 4556 KB Output is correct
110 Correct 56 ms 4484 KB Output is correct
111 Correct 48 ms 4560 KB Output is correct
112 Correct 47 ms 4464 KB Output is correct
113 Correct 49 ms 4556 KB Output is correct
114 Correct 51 ms 4556 KB Output is correct
115 Correct 65 ms 4492 KB Output is correct
116 Incorrect 1 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -