답안 #492932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492932 2021-12-09T19:30:56 Z blue Diversity (CEOI21_diversity) C++17
64 / 100
108 ms 9364 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;

using ll = long long;

int main()
{
    int N, Q;
    cin >> N >> Q;

    vector<int> ct(1+300'000, 0);
    for(int i = 1; i <= N; i++)
    {
        int a;
        cin >> a;
        ct[a]++;
    }

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

    vector<ll> val;
    for(int f = 1; f <= 300'000; f++)
        if(ct[f])
            val.push_back(ct[f]);

    sort(val.begin(), val.end(), [] (int u, int v)
    {
        return u > v;
    });

    deque<ll> val2;
    for(int i = 0; i < int(val.size()); i++)
    {
        if(i % 2 == 0) val2.push_back(val[i]);
        else val2.push_front(val[i]);
    }
    val2.push_front(0);

    int G = int(val2.size()) - 1;

    vector<ll> prefsum(1+G, 0);
    for(int i = 1; i <= G; i++) prefsum[i] = prefsum[i-1] + val2[i];

    // for(int f = 1; f <= G; f++) cerr << val2[f] << ' ';
    // cerr << '\n';

    ll res = 0;
    for(int i = 1; i <= G; i++)
    {
        res += (val2[i]*(val2[i]+1))/2 + prefsum[i-1]*val2[i] + (prefsum[G] - prefsum[i])*val2[i] + (prefsum[i-1])*(prefsum[G] - prefsum[i]);
        // cerr << "!\n";
        // cerr << (prefsum[G] - prefsum[i])*val2[i] << '\n';
        // cerr << (val2[i]*(val2[i]+1))/2 << '\n';
        // cerr << prefsum[i-1]*val2[i] << '\n';
        // cerr << (prefsum[i-1])*(prefsum[G] - prefsum[i]) << '\n';
        // cerr << i << " : " << (val2[i]*(val2[i]+1))/2 + prefsum[i-1]*val2[i] + (prefsum[G] - prefsum[i])*val2[i] * (prefsum[i-1])*(prefsum[G] - prefsum[i]);
        // cerr << '\n';
    }

    cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 1 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 16 ms 1668 KB Output is correct
5 Correct 25 ms 1840 KB Output is correct
6 Correct 41 ms 2092 KB Output is correct
7 Correct 39 ms 2060 KB Output is correct
8 Correct 40 ms 1960 KB Output is correct
9 Correct 39 ms 1968 KB Output is correct
10 Correct 50 ms 2244 KB Output is correct
11 Correct 40 ms 2092 KB Output is correct
12 Correct 42 ms 2116 KB Output is correct
13 Correct 44 ms 2088 KB Output is correct
14 Correct 40 ms 2116 KB Output is correct
15 Correct 40 ms 2084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 16 ms 1668 KB Output is correct
5 Correct 25 ms 1840 KB Output is correct
6 Correct 41 ms 2092 KB Output is correct
7 Correct 39 ms 2060 KB Output is correct
8 Correct 40 ms 1960 KB Output is correct
9 Correct 39 ms 1968 KB Output is correct
10 Correct 50 ms 2244 KB Output is correct
11 Correct 40 ms 2092 KB Output is correct
12 Correct 42 ms 2116 KB Output is correct
13 Correct 44 ms 2088 KB Output is correct
14 Correct 40 ms 2116 KB Output is correct
15 Correct 40 ms 2084 KB Output is correct
16 Correct 1 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
18 Correct 4 ms 1484 KB Output is correct
19 Correct 21 ms 1740 KB Output is correct
20 Correct 29 ms 1960 KB Output is correct
21 Correct 53 ms 2244 KB Output is correct
22 Correct 45 ms 2216 KB Output is correct
23 Correct 44 ms 2244 KB Output is correct
24 Correct 46 ms 2116 KB Output is correct
25 Correct 44 ms 2216 KB Output is correct
26 Correct 45 ms 2096 KB Output is correct
27 Correct 46 ms 2204 KB Output is correct
28 Correct 47 ms 2080 KB Output is correct
29 Correct 44 ms 2088 KB Output is correct
30 Correct 44 ms 2244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 16 ms 1668 KB Output is correct
5 Correct 25 ms 1840 KB Output is correct
6 Correct 41 ms 2092 KB Output is correct
7 Correct 39 ms 2060 KB Output is correct
8 Correct 40 ms 1960 KB Output is correct
9 Correct 39 ms 1968 KB Output is correct
10 Correct 50 ms 2244 KB Output is correct
11 Correct 40 ms 2092 KB Output is correct
12 Correct 42 ms 2116 KB Output is correct
13 Correct 44 ms 2088 KB Output is correct
14 Correct 40 ms 2116 KB Output is correct
15 Correct 40 ms 2084 KB Output is correct
16 Correct 1 ms 1356 KB Output is correct
17 Correct 1 ms 1356 KB Output is correct
18 Correct 4 ms 1484 KB Output is correct
19 Correct 21 ms 1740 KB Output is correct
20 Correct 29 ms 1960 KB Output is correct
21 Correct 53 ms 2244 KB Output is correct
22 Correct 45 ms 2216 KB Output is correct
23 Correct 44 ms 2244 KB Output is correct
24 Correct 46 ms 2116 KB Output is correct
25 Correct 44 ms 2216 KB Output is correct
26 Correct 45 ms 2096 KB Output is correct
27 Correct 46 ms 2204 KB Output is correct
28 Correct 47 ms 2080 KB Output is correct
29 Correct 44 ms 2088 KB Output is correct
30 Correct 44 ms 2244 KB Output is correct
31 Correct 1 ms 1356 KB Output is correct
32 Correct 1 ms 1484 KB Output is correct
33 Correct 1 ms 1356 KB Output is correct
34 Correct 3 ms 1500 KB Output is correct
35 Correct 3 ms 1484 KB Output is correct
36 Correct 3 ms 1612 KB Output is correct
37 Correct 10 ms 1612 KB Output is correct
38 Correct 12 ms 1672 KB Output is correct
39 Correct 22 ms 1852 KB Output is correct
40 Correct 43 ms 2216 KB Output is correct
41 Correct 56 ms 2600 KB Output is correct
42 Correct 55 ms 2604 KB Output is correct
43 Correct 57 ms 2584 KB Output is correct
44 Correct 69 ms 2588 KB Output is correct
45 Correct 62 ms 2596 KB Output is correct
46 Correct 60 ms 2604 KB Output is correct
47 Correct 58 ms 2608 KB Output is correct
48 Correct 56 ms 2596 KB Output is correct
49 Correct 56 ms 2500 KB Output is correct
50 Correct 56 ms 2500 KB Output is correct
51 Correct 57 ms 2588 KB Output is correct
52 Correct 62 ms 2628 KB Output is correct
53 Correct 58 ms 2600 KB Output is correct
54 Correct 57 ms 2600 KB Output is correct
55 Correct 55 ms 2600 KB Output is correct
56 Correct 55 ms 2592 KB Output is correct
57 Correct 55 ms 2588 KB Output is correct
58 Correct 56 ms 2628 KB Output is correct
59 Correct 63 ms 2720 KB Output is correct
60 Correct 56 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 1 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 1356 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 16 ms 1668 KB Output is correct
15 Correct 25 ms 1840 KB Output is correct
16 Correct 41 ms 2092 KB Output is correct
17 Correct 39 ms 2060 KB Output is correct
18 Correct 40 ms 1960 KB Output is correct
19 Correct 39 ms 1968 KB Output is correct
20 Correct 50 ms 2244 KB Output is correct
21 Correct 40 ms 2092 KB Output is correct
22 Correct 42 ms 2116 KB Output is correct
23 Correct 44 ms 2088 KB Output is correct
24 Correct 40 ms 2116 KB Output is correct
25 Correct 40 ms 2084 KB Output is correct
26 Correct 1 ms 1356 KB Output is correct
27 Correct 1 ms 1356 KB Output is correct
28 Correct 4 ms 1484 KB Output is correct
29 Correct 21 ms 1740 KB Output is correct
30 Correct 29 ms 1960 KB Output is correct
31 Correct 53 ms 2244 KB Output is correct
32 Correct 45 ms 2216 KB Output is correct
33 Correct 44 ms 2244 KB Output is correct
34 Correct 46 ms 2116 KB Output is correct
35 Correct 44 ms 2216 KB Output is correct
36 Correct 45 ms 2096 KB Output is correct
37 Correct 46 ms 2204 KB Output is correct
38 Correct 47 ms 2080 KB Output is correct
39 Correct 44 ms 2088 KB Output is correct
40 Correct 44 ms 2244 KB Output is correct
41 Correct 1 ms 1356 KB Output is correct
42 Correct 1 ms 1484 KB Output is correct
43 Correct 1 ms 1356 KB Output is correct
44 Correct 3 ms 1500 KB Output is correct
45 Correct 3 ms 1484 KB Output is correct
46 Correct 3 ms 1612 KB Output is correct
47 Correct 10 ms 1612 KB Output is correct
48 Correct 12 ms 1672 KB Output is correct
49 Correct 22 ms 1852 KB Output is correct
50 Correct 43 ms 2216 KB Output is correct
51 Correct 56 ms 2600 KB Output is correct
52 Correct 55 ms 2604 KB Output is correct
53 Correct 57 ms 2584 KB Output is correct
54 Correct 69 ms 2588 KB Output is correct
55 Correct 62 ms 2596 KB Output is correct
56 Correct 60 ms 2604 KB Output is correct
57 Correct 58 ms 2608 KB Output is correct
58 Correct 56 ms 2596 KB Output is correct
59 Correct 56 ms 2500 KB Output is correct
60 Correct 56 ms 2500 KB Output is correct
61 Correct 57 ms 2588 KB Output is correct
62 Correct 62 ms 2628 KB Output is correct
63 Correct 58 ms 2600 KB Output is correct
64 Correct 57 ms 2600 KB Output is correct
65 Correct 55 ms 2600 KB Output is correct
66 Correct 55 ms 2592 KB Output is correct
67 Correct 55 ms 2588 KB Output is correct
68 Correct 56 ms 2628 KB Output is correct
69 Correct 63 ms 2720 KB Output is correct
70 Correct 56 ms 2500 KB Output is correct
71 Correct 11 ms 1692 KB Output is correct
72 Correct 11 ms 1696 KB Output is correct
73 Correct 12 ms 1696 KB Output is correct
74 Correct 12 ms 1692 KB Output is correct
75 Correct 12 ms 1692 KB Output is correct
76 Correct 22 ms 1988 KB Output is correct
77 Correct 23 ms 2068 KB Output is correct
78 Correct 22 ms 2064 KB Output is correct
79 Correct 22 ms 1968 KB Output is correct
80 Correct 23 ms 2060 KB Output is correct
81 Correct 50 ms 2588 KB Output is correct
82 Correct 47 ms 2596 KB Output is correct
83 Correct 45 ms 2604 KB Output is correct
84 Correct 43 ms 2628 KB Output is correct
85 Correct 44 ms 2628 KB Output is correct
86 Correct 49 ms 3008 KB Output is correct
87 Correct 47 ms 2984 KB Output is correct
88 Correct 47 ms 2980 KB Output is correct
89 Correct 47 ms 2984 KB Output is correct
90 Correct 48 ms 3008 KB Output is correct
91 Correct 88 ms 5536 KB Output is correct
92 Correct 79 ms 5520 KB Output is correct
93 Correct 79 ms 5528 KB Output is correct
94 Correct 77 ms 5516 KB Output is correct
95 Correct 81 ms 5476 KB Output is correct
96 Correct 85 ms 8076 KB Output is correct
97 Correct 91 ms 8076 KB Output is correct
98 Correct 87 ms 8116 KB Output is correct
99 Correct 88 ms 8076 KB Output is correct
100 Correct 92 ms 8076 KB Output is correct
101 Correct 88 ms 8084 KB Output is correct
102 Correct 108 ms 8080 KB Output is correct
103 Correct 95 ms 8116 KB Output is correct
104 Correct 89 ms 8092 KB Output is correct
105 Correct 94 ms 8072 KB Output is correct
106 Correct 88 ms 9364 KB Output is correct
107 Correct 100 ms 9356 KB Output is correct
108 Correct 93 ms 9364 KB Output is correct
109 Correct 90 ms 9244 KB Output is correct
110 Correct 88 ms 9356 KB Output is correct
111 Correct 89 ms 9268 KB Output is correct
112 Correct 93 ms 9360 KB Output is correct
113 Correct 93 ms 9364 KB Output is correct
114 Correct 87 ms 9268 KB Output is correct
115 Correct 93 ms 9352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 1 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 1356 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 16 ms 1668 KB Output is correct
15 Correct 25 ms 1840 KB Output is correct
16 Correct 41 ms 2092 KB Output is correct
17 Correct 39 ms 2060 KB Output is correct
18 Correct 40 ms 1960 KB Output is correct
19 Correct 39 ms 1968 KB Output is correct
20 Correct 50 ms 2244 KB Output is correct
21 Correct 40 ms 2092 KB Output is correct
22 Correct 42 ms 2116 KB Output is correct
23 Correct 44 ms 2088 KB Output is correct
24 Correct 40 ms 2116 KB Output is correct
25 Correct 40 ms 2084 KB Output is correct
26 Correct 1 ms 1356 KB Output is correct
27 Correct 1 ms 1356 KB Output is correct
28 Correct 4 ms 1484 KB Output is correct
29 Correct 21 ms 1740 KB Output is correct
30 Correct 29 ms 1960 KB Output is correct
31 Correct 53 ms 2244 KB Output is correct
32 Correct 45 ms 2216 KB Output is correct
33 Correct 44 ms 2244 KB Output is correct
34 Correct 46 ms 2116 KB Output is correct
35 Correct 44 ms 2216 KB Output is correct
36 Correct 45 ms 2096 KB Output is correct
37 Correct 46 ms 2204 KB Output is correct
38 Correct 47 ms 2080 KB Output is correct
39 Correct 44 ms 2088 KB Output is correct
40 Correct 44 ms 2244 KB Output is correct
41 Correct 1 ms 1356 KB Output is correct
42 Correct 1 ms 1484 KB Output is correct
43 Correct 1 ms 1356 KB Output is correct
44 Correct 3 ms 1500 KB Output is correct
45 Correct 3 ms 1484 KB Output is correct
46 Correct 3 ms 1612 KB Output is correct
47 Correct 10 ms 1612 KB Output is correct
48 Correct 12 ms 1672 KB Output is correct
49 Correct 22 ms 1852 KB Output is correct
50 Correct 43 ms 2216 KB Output is correct
51 Correct 56 ms 2600 KB Output is correct
52 Correct 55 ms 2604 KB Output is correct
53 Correct 57 ms 2584 KB Output is correct
54 Correct 69 ms 2588 KB Output is correct
55 Correct 62 ms 2596 KB Output is correct
56 Correct 60 ms 2604 KB Output is correct
57 Correct 58 ms 2608 KB Output is correct
58 Correct 56 ms 2596 KB Output is correct
59 Correct 56 ms 2500 KB Output is correct
60 Correct 56 ms 2500 KB Output is correct
61 Correct 57 ms 2588 KB Output is correct
62 Correct 62 ms 2628 KB Output is correct
63 Correct 58 ms 2600 KB Output is correct
64 Correct 57 ms 2600 KB Output is correct
65 Correct 55 ms 2600 KB Output is correct
66 Correct 55 ms 2592 KB Output is correct
67 Correct 55 ms 2588 KB Output is correct
68 Correct 56 ms 2628 KB Output is correct
69 Correct 63 ms 2720 KB Output is correct
70 Correct 56 ms 2500 KB Output is correct
71 Correct 11 ms 1692 KB Output is correct
72 Correct 11 ms 1696 KB Output is correct
73 Correct 12 ms 1696 KB Output is correct
74 Correct 12 ms 1692 KB Output is correct
75 Correct 12 ms 1692 KB Output is correct
76 Correct 22 ms 1988 KB Output is correct
77 Correct 23 ms 2068 KB Output is correct
78 Correct 22 ms 2064 KB Output is correct
79 Correct 22 ms 1968 KB Output is correct
80 Correct 23 ms 2060 KB Output is correct
81 Correct 50 ms 2588 KB Output is correct
82 Correct 47 ms 2596 KB Output is correct
83 Correct 45 ms 2604 KB Output is correct
84 Correct 43 ms 2628 KB Output is correct
85 Correct 44 ms 2628 KB Output is correct
86 Correct 49 ms 3008 KB Output is correct
87 Correct 47 ms 2984 KB Output is correct
88 Correct 47 ms 2980 KB Output is correct
89 Correct 47 ms 2984 KB Output is correct
90 Correct 48 ms 3008 KB Output is correct
91 Correct 88 ms 5536 KB Output is correct
92 Correct 79 ms 5520 KB Output is correct
93 Correct 79 ms 5528 KB Output is correct
94 Correct 77 ms 5516 KB Output is correct
95 Correct 81 ms 5476 KB Output is correct
96 Correct 85 ms 8076 KB Output is correct
97 Correct 91 ms 8076 KB Output is correct
98 Correct 87 ms 8116 KB Output is correct
99 Correct 88 ms 8076 KB Output is correct
100 Correct 92 ms 8076 KB Output is correct
101 Correct 88 ms 8084 KB Output is correct
102 Correct 108 ms 8080 KB Output is correct
103 Correct 95 ms 8116 KB Output is correct
104 Correct 89 ms 8092 KB Output is correct
105 Correct 94 ms 8072 KB Output is correct
106 Correct 88 ms 9364 KB Output is correct
107 Correct 100 ms 9356 KB Output is correct
108 Correct 93 ms 9364 KB Output is correct
109 Correct 90 ms 9244 KB Output is correct
110 Correct 88 ms 9356 KB Output is correct
111 Correct 89 ms 9268 KB Output is correct
112 Correct 93 ms 9360 KB Output is correct
113 Correct 93 ms 9364 KB Output is correct
114 Correct 87 ms 9268 KB Output is correct
115 Correct 93 ms 9352 KB Output is correct
116 Incorrect 3 ms 1484 KB Output isn't correct
117 Halted 0 ms 0 KB -