답안 #858007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858007 2023-10-07T09:40:06 Z danikoynov Diversity (CEOI21_diversity) C++14
64 / 100
76 ms 16060 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 3e5 + 10;

int n, q, a[maxn], cnt[maxn], m;
ll bef[maxn], aft[maxn], pref[maxn];
const ll inf = 1e18;
vector < ll > groups;
ll val[maxn];

void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];

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

    for (int i = 1; i <= n; i ++)
        cnt[a[i]] ++;


    for (int i = 1; i <= n; i ++)
        if (cnt[i] > 0)
            groups.push_back((ll)(cnt[i]));

    m = groups.size();
    sort(groups.begin(), groups.end());
    reverse(groups.begin(), groups.end());
    l = (m + 1) / 2;
    r = (m + 1) / 2;
    val[l] = groups[0];
    for (int i = 1; i < m; i ++)
    {
        if (l == 1)
        {
            val[++ r] = groups[i];
        }
        else if (r == n)
        {
            val[-- l] = groups[i];
        }
        else
        {
            if (i % 2 == 1)
            {
                val[++ r] = groups[i];
            }
            else
            {
                val[-- l] = groups[i];
            }
        }
    }


    ll tot = 0;
    ll bf = 0;
    for (int i = 1; i <= m; i ++)
    {
        bef[i] = bf;
        bf += val[i];
    }
    ll af = 0;
    for (int i = m ; i > 0; i --)
    {
        aft[i] = af;
        af += val[i];
    }

    for (ll i = 1; i <= m; i ++)
    {
        tot = tot + i * val[i] * (bef[i] - aft[i]);
    }

    ll sf = 0;
    for (int i = 1; i <= m; i ++)
    {
        ll cur = val[i];
        tot = tot + cur * (cur + 1) / 2;
        tot = tot + val[i] * sf;
        sf += val[i];
    }

    cout << tot << endl;
}

int main()
{
    solve();
    return 0;
}
/**
4 1
1 1 1 1
1 2
2 4

4 1
2 1 3 2
1 4

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 12 ms 8992 KB Output is correct
5 Correct 22 ms 9308 KB Output is correct
6 Correct 36 ms 9708 KB Output is correct
7 Correct 34 ms 9552 KB Output is correct
8 Correct 34 ms 9556 KB Output is correct
9 Correct 34 ms 9552 KB Output is correct
10 Correct 37 ms 9708 KB Output is correct
11 Correct 34 ms 9552 KB Output is correct
12 Correct 35 ms 9808 KB Output is correct
13 Correct 34 ms 9556 KB Output is correct
14 Correct 34 ms 9556 KB Output is correct
15 Correct 33 ms 9548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 12 ms 8992 KB Output is correct
5 Correct 22 ms 9308 KB Output is correct
6 Correct 36 ms 9708 KB Output is correct
7 Correct 34 ms 9552 KB Output is correct
8 Correct 34 ms 9556 KB Output is correct
9 Correct 34 ms 9552 KB Output is correct
10 Correct 37 ms 9708 KB Output is correct
11 Correct 34 ms 9552 KB Output is correct
12 Correct 35 ms 9808 KB Output is correct
13 Correct 34 ms 9556 KB Output is correct
14 Correct 34 ms 9556 KB Output is correct
15 Correct 33 ms 9548 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 14 ms 9248 KB Output is correct
20 Correct 26 ms 9820 KB Output is correct
21 Correct 39 ms 10576 KB Output is correct
22 Correct 38 ms 10576 KB Output is correct
23 Correct 38 ms 10580 KB Output is correct
24 Correct 38 ms 10576 KB Output is correct
25 Correct 38 ms 10576 KB Output is correct
26 Correct 38 ms 10324 KB Output is correct
27 Correct 40 ms 10576 KB Output is correct
28 Correct 37 ms 10320 KB Output is correct
29 Correct 42 ms 10324 KB Output is correct
30 Correct 48 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 12 ms 8992 KB Output is correct
5 Correct 22 ms 9308 KB Output is correct
6 Correct 36 ms 9708 KB Output is correct
7 Correct 34 ms 9552 KB Output is correct
8 Correct 34 ms 9556 KB Output is correct
9 Correct 34 ms 9552 KB Output is correct
10 Correct 37 ms 9708 KB Output is correct
11 Correct 34 ms 9552 KB Output is correct
12 Correct 35 ms 9808 KB Output is correct
13 Correct 34 ms 9556 KB Output is correct
14 Correct 34 ms 9556 KB Output is correct
15 Correct 33 ms 9548 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 14 ms 9248 KB Output is correct
20 Correct 26 ms 9820 KB Output is correct
21 Correct 39 ms 10576 KB Output is correct
22 Correct 38 ms 10576 KB Output is correct
23 Correct 38 ms 10580 KB Output is correct
24 Correct 38 ms 10576 KB Output is correct
25 Correct 38 ms 10576 KB Output is correct
26 Correct 38 ms 10324 KB Output is correct
27 Correct 40 ms 10576 KB Output is correct
28 Correct 37 ms 10320 KB Output is correct
29 Correct 42 ms 10324 KB Output is correct
30 Correct 48 ms 10576 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 2 ms 8536 KB Output is correct
33 Correct 2 ms 8536 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 8 ms 8948 KB Output is correct
38 Correct 9 ms 9052 KB Output is correct
39 Correct 15 ms 9416 KB Output is correct
40 Correct 30 ms 10076 KB Output is correct
41 Correct 44 ms 10832 KB Output is correct
42 Correct 44 ms 10840 KB Output is correct
43 Correct 47 ms 10904 KB Output is correct
44 Correct 44 ms 10748 KB Output is correct
45 Correct 45 ms 10960 KB Output is correct
46 Correct 44 ms 10832 KB Output is correct
47 Correct 45 ms 10836 KB Output is correct
48 Correct 47 ms 10840 KB Output is correct
49 Correct 43 ms 10832 KB Output is correct
50 Correct 44 ms 11020 KB Output is correct
51 Correct 44 ms 10836 KB Output is correct
52 Correct 46 ms 10956 KB Output is correct
53 Correct 45 ms 10752 KB Output is correct
54 Correct 44 ms 10832 KB Output is correct
55 Correct 44 ms 10832 KB Output is correct
56 Correct 44 ms 10916 KB Output is correct
57 Correct 45 ms 10720 KB Output is correct
58 Correct 48 ms 10760 KB Output is correct
59 Correct 44 ms 11100 KB Output is correct
60 Correct 44 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 12 ms 8992 KB Output is correct
15 Correct 22 ms 9308 KB Output is correct
16 Correct 36 ms 9708 KB Output is correct
17 Correct 34 ms 9552 KB Output is correct
18 Correct 34 ms 9556 KB Output is correct
19 Correct 34 ms 9552 KB Output is correct
20 Correct 37 ms 9708 KB Output is correct
21 Correct 34 ms 9552 KB Output is correct
22 Correct 35 ms 9808 KB Output is correct
23 Correct 34 ms 9556 KB Output is correct
24 Correct 34 ms 9556 KB Output is correct
25 Correct 33 ms 9548 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 3 ms 8540 KB Output is correct
29 Correct 14 ms 9248 KB Output is correct
30 Correct 26 ms 9820 KB Output is correct
31 Correct 39 ms 10576 KB Output is correct
32 Correct 38 ms 10576 KB Output is correct
33 Correct 38 ms 10580 KB Output is correct
34 Correct 38 ms 10576 KB Output is correct
35 Correct 38 ms 10576 KB Output is correct
36 Correct 38 ms 10324 KB Output is correct
37 Correct 40 ms 10576 KB Output is correct
38 Correct 37 ms 10320 KB Output is correct
39 Correct 42 ms 10324 KB Output is correct
40 Correct 48 ms 10576 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 2 ms 8536 KB Output is correct
43 Correct 2 ms 8536 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 8 ms 8948 KB Output is correct
48 Correct 9 ms 9052 KB Output is correct
49 Correct 15 ms 9416 KB Output is correct
50 Correct 30 ms 10076 KB Output is correct
51 Correct 44 ms 10832 KB Output is correct
52 Correct 44 ms 10840 KB Output is correct
53 Correct 47 ms 10904 KB Output is correct
54 Correct 44 ms 10748 KB Output is correct
55 Correct 45 ms 10960 KB Output is correct
56 Correct 44 ms 10832 KB Output is correct
57 Correct 45 ms 10836 KB Output is correct
58 Correct 47 ms 10840 KB Output is correct
59 Correct 43 ms 10832 KB Output is correct
60 Correct 44 ms 11020 KB Output is correct
61 Correct 44 ms 10836 KB Output is correct
62 Correct 46 ms 10956 KB Output is correct
63 Correct 45 ms 10752 KB Output is correct
64 Correct 44 ms 10832 KB Output is correct
65 Correct 44 ms 10832 KB Output is correct
66 Correct 44 ms 10916 KB Output is correct
67 Correct 45 ms 10720 KB Output is correct
68 Correct 48 ms 10760 KB Output is correct
69 Correct 44 ms 11100 KB Output is correct
70 Correct 44 ms 10832 KB Output is correct
71 Correct 13 ms 9052 KB Output is correct
72 Correct 9 ms 9012 KB Output is correct
73 Correct 10 ms 9052 KB Output is correct
74 Correct 9 ms 9048 KB Output is correct
75 Correct 9 ms 9016 KB Output is correct
76 Correct 18 ms 9564 KB Output is correct
77 Correct 18 ms 9564 KB Output is correct
78 Correct 20 ms 9564 KB Output is correct
79 Correct 19 ms 9444 KB Output is correct
80 Correct 19 ms 9564 KB Output is correct
81 Correct 36 ms 10580 KB Output is correct
82 Correct 36 ms 10604 KB Output is correct
83 Correct 36 ms 10576 KB Output is correct
84 Correct 37 ms 10588 KB Output is correct
85 Correct 43 ms 10872 KB Output is correct
86 Correct 38 ms 10848 KB Output is correct
87 Correct 38 ms 10780 KB Output is correct
88 Correct 38 ms 10860 KB Output is correct
89 Correct 40 ms 10700 KB Output is correct
90 Correct 41 ms 10700 KB Output is correct
91 Correct 62 ms 14628 KB Output is correct
92 Correct 61 ms 14536 KB Output is correct
93 Correct 62 ms 14520 KB Output is correct
94 Correct 61 ms 14504 KB Output is correct
95 Correct 61 ms 14680 KB Output is correct
96 Correct 72 ms 15808 KB Output is correct
97 Correct 67 ms 15536 KB Output is correct
98 Correct 66 ms 15512 KB Output is correct
99 Correct 71 ms 15452 KB Output is correct
100 Correct 68 ms 15376 KB Output is correct
101 Correct 71 ms 15552 KB Output is correct
102 Correct 67 ms 15556 KB Output is correct
103 Correct 67 ms 15556 KB Output is correct
104 Correct 66 ms 15496 KB Output is correct
105 Correct 67 ms 15548 KB Output is correct
106 Correct 70 ms 15900 KB Output is correct
107 Correct 73 ms 15808 KB Output is correct
108 Correct 69 ms 15808 KB Output is correct
109 Correct 71 ms 16052 KB Output is correct
110 Correct 76 ms 15972 KB Output is correct
111 Correct 71 ms 15912 KB Output is correct
112 Correct 68 ms 16040 KB Output is correct
113 Correct 68 ms 15808 KB Output is correct
114 Correct 69 ms 15816 KB Output is correct
115 Correct 70 ms 16060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 12 ms 8992 KB Output is correct
15 Correct 22 ms 9308 KB Output is correct
16 Correct 36 ms 9708 KB Output is correct
17 Correct 34 ms 9552 KB Output is correct
18 Correct 34 ms 9556 KB Output is correct
19 Correct 34 ms 9552 KB Output is correct
20 Correct 37 ms 9708 KB Output is correct
21 Correct 34 ms 9552 KB Output is correct
22 Correct 35 ms 9808 KB Output is correct
23 Correct 34 ms 9556 KB Output is correct
24 Correct 34 ms 9556 KB Output is correct
25 Correct 33 ms 9548 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 3 ms 8540 KB Output is correct
29 Correct 14 ms 9248 KB Output is correct
30 Correct 26 ms 9820 KB Output is correct
31 Correct 39 ms 10576 KB Output is correct
32 Correct 38 ms 10576 KB Output is correct
33 Correct 38 ms 10580 KB Output is correct
34 Correct 38 ms 10576 KB Output is correct
35 Correct 38 ms 10576 KB Output is correct
36 Correct 38 ms 10324 KB Output is correct
37 Correct 40 ms 10576 KB Output is correct
38 Correct 37 ms 10320 KB Output is correct
39 Correct 42 ms 10324 KB Output is correct
40 Correct 48 ms 10576 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 2 ms 8536 KB Output is correct
43 Correct 2 ms 8536 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 8 ms 8948 KB Output is correct
48 Correct 9 ms 9052 KB Output is correct
49 Correct 15 ms 9416 KB Output is correct
50 Correct 30 ms 10076 KB Output is correct
51 Correct 44 ms 10832 KB Output is correct
52 Correct 44 ms 10840 KB Output is correct
53 Correct 47 ms 10904 KB Output is correct
54 Correct 44 ms 10748 KB Output is correct
55 Correct 45 ms 10960 KB Output is correct
56 Correct 44 ms 10832 KB Output is correct
57 Correct 45 ms 10836 KB Output is correct
58 Correct 47 ms 10840 KB Output is correct
59 Correct 43 ms 10832 KB Output is correct
60 Correct 44 ms 11020 KB Output is correct
61 Correct 44 ms 10836 KB Output is correct
62 Correct 46 ms 10956 KB Output is correct
63 Correct 45 ms 10752 KB Output is correct
64 Correct 44 ms 10832 KB Output is correct
65 Correct 44 ms 10832 KB Output is correct
66 Correct 44 ms 10916 KB Output is correct
67 Correct 45 ms 10720 KB Output is correct
68 Correct 48 ms 10760 KB Output is correct
69 Correct 44 ms 11100 KB Output is correct
70 Correct 44 ms 10832 KB Output is correct
71 Correct 13 ms 9052 KB Output is correct
72 Correct 9 ms 9012 KB Output is correct
73 Correct 10 ms 9052 KB Output is correct
74 Correct 9 ms 9048 KB Output is correct
75 Correct 9 ms 9016 KB Output is correct
76 Correct 18 ms 9564 KB Output is correct
77 Correct 18 ms 9564 KB Output is correct
78 Correct 20 ms 9564 KB Output is correct
79 Correct 19 ms 9444 KB Output is correct
80 Correct 19 ms 9564 KB Output is correct
81 Correct 36 ms 10580 KB Output is correct
82 Correct 36 ms 10604 KB Output is correct
83 Correct 36 ms 10576 KB Output is correct
84 Correct 37 ms 10588 KB Output is correct
85 Correct 43 ms 10872 KB Output is correct
86 Correct 38 ms 10848 KB Output is correct
87 Correct 38 ms 10780 KB Output is correct
88 Correct 38 ms 10860 KB Output is correct
89 Correct 40 ms 10700 KB Output is correct
90 Correct 41 ms 10700 KB Output is correct
91 Correct 62 ms 14628 KB Output is correct
92 Correct 61 ms 14536 KB Output is correct
93 Correct 62 ms 14520 KB Output is correct
94 Correct 61 ms 14504 KB Output is correct
95 Correct 61 ms 14680 KB Output is correct
96 Correct 72 ms 15808 KB Output is correct
97 Correct 67 ms 15536 KB Output is correct
98 Correct 66 ms 15512 KB Output is correct
99 Correct 71 ms 15452 KB Output is correct
100 Correct 68 ms 15376 KB Output is correct
101 Correct 71 ms 15552 KB Output is correct
102 Correct 67 ms 15556 KB Output is correct
103 Correct 67 ms 15556 KB Output is correct
104 Correct 66 ms 15496 KB Output is correct
105 Correct 67 ms 15548 KB Output is correct
106 Correct 70 ms 15900 KB Output is correct
107 Correct 73 ms 15808 KB Output is correct
108 Correct 69 ms 15808 KB Output is correct
109 Correct 71 ms 16052 KB Output is correct
110 Correct 76 ms 15972 KB Output is correct
111 Correct 71 ms 15912 KB Output is correct
112 Correct 68 ms 16040 KB Output is correct
113 Correct 68 ms 15808 KB Output is correct
114 Correct 69 ms 15816 KB Output is correct
115 Correct 70 ms 16060 KB Output is correct
116 Incorrect 2 ms 8792 KB Output isn't correct
117 Halted 0 ms 0 KB -