Submission #601625

# Submission time Handle Problem Language Result Execution time Memory
601625 2022-07-22T08:45:43 Z Valaki2 Diversity (CEOI21_diversity) C++14
64 / 100
56 ms 6384 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 3e5;

int n, q;
int base_cnt[maxn + 1];
int ans;
vector<int> v;

void solve() {
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        base_cnt[x]++;
    }
    for(int i = 1; i <= maxn; i++) {
        if(base_cnt[i] != 0) {
            int x = base_cnt[i];
            ans += (x * (x + 1)) / 2;
            v.pb(x);
        }
    }
    n = v.size();
    sort(v.rbegin(), v.rend());
    int lsum = 0, rsum = 0, sum = 0, cnt = 0;
    for(int cur : v) {
        cnt++;
        if(lsum < rsum) {
            ans += cur * lsum;
            lsum += sum;
            lsum += 2 * cur;
            rsum += (cnt + 1) * cur;
        } else {
            ans += cur * rsum;
            rsum += sum;
            rsum += 2 * cur;
            lsum += (cnt + 1) * cur;
        }
        sum += cur;
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

/*
19 1
1 2 3 3 4 4 4 5 5 5 5 5 6 6 6 6 6 6 6
1 19
*/
# 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 2 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 440 KB Output is correct
5 Correct 11 ms 744 KB Output is correct
6 Correct 18 ms 980 KB Output is correct
7 Correct 16 ms 944 KB Output is correct
8 Correct 24 ms 856 KB Output is correct
9 Correct 16 ms 852 KB Output is correct
10 Correct 26 ms 948 KB Output is correct
11 Correct 20 ms 960 KB Output is correct
12 Correct 25 ms 976 KB Output is correct
13 Correct 24 ms 948 KB Output is correct
14 Correct 23 ms 948 KB Output is correct
15 Correct 16 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 440 KB Output is correct
5 Correct 11 ms 744 KB Output is correct
6 Correct 18 ms 980 KB Output is correct
7 Correct 16 ms 944 KB Output is correct
8 Correct 24 ms 856 KB Output is correct
9 Correct 16 ms 852 KB Output is correct
10 Correct 26 ms 948 KB Output is correct
11 Correct 20 ms 960 KB Output is correct
12 Correct 25 ms 976 KB Output is correct
13 Correct 24 ms 948 KB Output is correct
14 Correct 23 ms 948 KB Output is correct
15 Correct 16 ms 964 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 340 KB Output is correct
19 Correct 6 ms 596 KB Output is correct
20 Correct 18 ms 828 KB Output is correct
21 Correct 18 ms 1084 KB Output is correct
22 Correct 18 ms 1108 KB Output is correct
23 Correct 20 ms 1080 KB Output is correct
24 Correct 18 ms 1084 KB Output is correct
25 Correct 28 ms 972 KB Output is correct
26 Correct 23 ms 1072 KB Output is correct
27 Correct 19 ms 1084 KB Output is correct
28 Correct 18 ms 980 KB Output is correct
29 Correct 23 ms 956 KB Output is correct
30 Correct 19 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 440 KB Output is correct
5 Correct 11 ms 744 KB Output is correct
6 Correct 18 ms 980 KB Output is correct
7 Correct 16 ms 944 KB Output is correct
8 Correct 24 ms 856 KB Output is correct
9 Correct 16 ms 852 KB Output is correct
10 Correct 26 ms 948 KB Output is correct
11 Correct 20 ms 960 KB Output is correct
12 Correct 25 ms 976 KB Output is correct
13 Correct 24 ms 948 KB Output is correct
14 Correct 23 ms 948 KB Output is correct
15 Correct 16 ms 964 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 340 KB Output is correct
19 Correct 6 ms 596 KB Output is correct
20 Correct 18 ms 828 KB Output is correct
21 Correct 18 ms 1084 KB Output is correct
22 Correct 18 ms 1108 KB Output is correct
23 Correct 20 ms 1080 KB Output is correct
24 Correct 18 ms 1084 KB Output is correct
25 Correct 28 ms 972 KB Output is correct
26 Correct 23 ms 1072 KB Output is correct
27 Correct 19 ms 1084 KB Output is correct
28 Correct 18 ms 980 KB Output is correct
29 Correct 23 ms 956 KB Output is correct
30 Correct 19 ms 1108 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 440 KB Output is correct
38 Correct 6 ms 468 KB Output is correct
39 Correct 12 ms 724 KB Output is correct
40 Correct 19 ms 1092 KB Output is correct
41 Correct 36 ms 1460 KB Output is correct
42 Correct 33 ms 1468 KB Output is correct
43 Correct 20 ms 1492 KB Output is correct
44 Correct 32 ms 1468 KB Output is correct
45 Correct 20 ms 1472 KB Output is correct
46 Correct 29 ms 1464 KB Output is correct
47 Correct 32 ms 1472 KB Output is correct
48 Correct 25 ms 1476 KB Output is correct
49 Correct 26 ms 1472 KB Output is correct
50 Correct 19 ms 1472 KB Output is correct
51 Correct 19 ms 1476 KB Output is correct
52 Correct 19 ms 1456 KB Output is correct
53 Correct 20 ms 1472 KB Output is correct
54 Correct 31 ms 1480 KB Output is correct
55 Correct 20 ms 1456 KB Output is correct
56 Correct 19 ms 1460 KB Output is correct
57 Correct 30 ms 1464 KB Output is correct
58 Correct 26 ms 1456 KB Output is correct
59 Correct 21 ms 1484 KB Output is correct
60 Correct 31 ms 1460 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 2 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 7 ms 440 KB Output is correct
15 Correct 11 ms 744 KB Output is correct
16 Correct 18 ms 980 KB Output is correct
17 Correct 16 ms 944 KB Output is correct
18 Correct 24 ms 856 KB Output is correct
19 Correct 16 ms 852 KB Output is correct
20 Correct 26 ms 948 KB Output is correct
21 Correct 20 ms 960 KB Output is correct
22 Correct 25 ms 976 KB Output is correct
23 Correct 24 ms 948 KB Output is correct
24 Correct 23 ms 948 KB Output is correct
25 Correct 16 ms 964 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 340 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 18 ms 828 KB Output is correct
31 Correct 18 ms 1084 KB Output is correct
32 Correct 18 ms 1108 KB Output is correct
33 Correct 20 ms 1080 KB Output is correct
34 Correct 18 ms 1084 KB Output is correct
35 Correct 28 ms 972 KB Output is correct
36 Correct 23 ms 1072 KB Output is correct
37 Correct 19 ms 1084 KB Output is correct
38 Correct 18 ms 980 KB Output is correct
39 Correct 23 ms 956 KB Output is correct
40 Correct 19 ms 1108 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 440 KB Output is correct
48 Correct 6 ms 468 KB Output is correct
49 Correct 12 ms 724 KB Output is correct
50 Correct 19 ms 1092 KB Output is correct
51 Correct 36 ms 1460 KB Output is correct
52 Correct 33 ms 1468 KB Output is correct
53 Correct 20 ms 1492 KB Output is correct
54 Correct 32 ms 1468 KB Output is correct
55 Correct 20 ms 1472 KB Output is correct
56 Correct 29 ms 1464 KB Output is correct
57 Correct 32 ms 1472 KB Output is correct
58 Correct 25 ms 1476 KB Output is correct
59 Correct 26 ms 1472 KB Output is correct
60 Correct 19 ms 1472 KB Output is correct
61 Correct 19 ms 1476 KB Output is correct
62 Correct 19 ms 1456 KB Output is correct
63 Correct 20 ms 1472 KB Output is correct
64 Correct 31 ms 1480 KB Output is correct
65 Correct 20 ms 1456 KB Output is correct
66 Correct 19 ms 1460 KB Output is correct
67 Correct 30 ms 1464 KB Output is correct
68 Correct 26 ms 1456 KB Output is correct
69 Correct 21 ms 1484 KB Output is correct
70 Correct 31 ms 1460 KB Output is correct
71 Correct 5 ms 596 KB Output is correct
72 Correct 5 ms 580 KB Output is correct
73 Correct 7 ms 604 KB Output is correct
74 Correct 4 ms 560 KB Output is correct
75 Correct 5 ms 596 KB Output is correct
76 Correct 11 ms 852 KB Output is correct
77 Correct 12 ms 852 KB Output is correct
78 Correct 9 ms 860 KB Output is correct
79 Correct 10 ms 868 KB Output is correct
80 Correct 9 ms 868 KB Output is correct
81 Correct 16 ms 1472 KB Output is correct
82 Correct 24 ms 1548 KB Output is correct
83 Correct 22 ms 1488 KB Output is correct
84 Correct 24 ms 1468 KB Output is correct
85 Correct 18 ms 1540 KB Output is correct
86 Correct 20 ms 1932 KB Output is correct
87 Correct 22 ms 1876 KB Output is correct
88 Correct 18 ms 1856 KB Output is correct
89 Correct 24 ms 1872 KB Output is correct
90 Correct 20 ms 1928 KB Output is correct
91 Correct 29 ms 3916 KB Output is correct
92 Correct 37 ms 3912 KB Output is correct
93 Correct 26 ms 3904 KB Output is correct
94 Correct 29 ms 3916 KB Output is correct
95 Correct 29 ms 3976 KB Output is correct
96 Correct 37 ms 5952 KB Output is correct
97 Correct 44 ms 5972 KB Output is correct
98 Correct 48 ms 5932 KB Output is correct
99 Correct 42 ms 5960 KB Output is correct
100 Correct 41 ms 5936 KB Output is correct
101 Correct 37 ms 5960 KB Output is correct
102 Correct 43 ms 5960 KB Output is correct
103 Correct 38 ms 5944 KB Output is correct
104 Correct 43 ms 5952 KB Output is correct
105 Correct 35 ms 5960 KB Output is correct
106 Correct 36 ms 6344 KB Output is correct
107 Correct 56 ms 6344 KB Output is correct
108 Correct 35 ms 6356 KB Output is correct
109 Correct 37 ms 6348 KB Output is correct
110 Correct 45 ms 6340 KB Output is correct
111 Correct 36 ms 6344 KB Output is correct
112 Correct 37 ms 6352 KB Output is correct
113 Correct 39 ms 6384 KB Output is correct
114 Correct 32 ms 6364 KB Output is correct
115 Correct 32 ms 6364 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 2 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 7 ms 440 KB Output is correct
15 Correct 11 ms 744 KB Output is correct
16 Correct 18 ms 980 KB Output is correct
17 Correct 16 ms 944 KB Output is correct
18 Correct 24 ms 856 KB Output is correct
19 Correct 16 ms 852 KB Output is correct
20 Correct 26 ms 948 KB Output is correct
21 Correct 20 ms 960 KB Output is correct
22 Correct 25 ms 976 KB Output is correct
23 Correct 24 ms 948 KB Output is correct
24 Correct 23 ms 948 KB Output is correct
25 Correct 16 ms 964 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 340 KB Output is correct
29 Correct 6 ms 596 KB Output is correct
30 Correct 18 ms 828 KB Output is correct
31 Correct 18 ms 1084 KB Output is correct
32 Correct 18 ms 1108 KB Output is correct
33 Correct 20 ms 1080 KB Output is correct
34 Correct 18 ms 1084 KB Output is correct
35 Correct 28 ms 972 KB Output is correct
36 Correct 23 ms 1072 KB Output is correct
37 Correct 19 ms 1084 KB Output is correct
38 Correct 18 ms 980 KB Output is correct
39 Correct 23 ms 956 KB Output is correct
40 Correct 19 ms 1108 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 440 KB Output is correct
48 Correct 6 ms 468 KB Output is correct
49 Correct 12 ms 724 KB Output is correct
50 Correct 19 ms 1092 KB Output is correct
51 Correct 36 ms 1460 KB Output is correct
52 Correct 33 ms 1468 KB Output is correct
53 Correct 20 ms 1492 KB Output is correct
54 Correct 32 ms 1468 KB Output is correct
55 Correct 20 ms 1472 KB Output is correct
56 Correct 29 ms 1464 KB Output is correct
57 Correct 32 ms 1472 KB Output is correct
58 Correct 25 ms 1476 KB Output is correct
59 Correct 26 ms 1472 KB Output is correct
60 Correct 19 ms 1472 KB Output is correct
61 Correct 19 ms 1476 KB Output is correct
62 Correct 19 ms 1456 KB Output is correct
63 Correct 20 ms 1472 KB Output is correct
64 Correct 31 ms 1480 KB Output is correct
65 Correct 20 ms 1456 KB Output is correct
66 Correct 19 ms 1460 KB Output is correct
67 Correct 30 ms 1464 KB Output is correct
68 Correct 26 ms 1456 KB Output is correct
69 Correct 21 ms 1484 KB Output is correct
70 Correct 31 ms 1460 KB Output is correct
71 Correct 5 ms 596 KB Output is correct
72 Correct 5 ms 580 KB Output is correct
73 Correct 7 ms 604 KB Output is correct
74 Correct 4 ms 560 KB Output is correct
75 Correct 5 ms 596 KB Output is correct
76 Correct 11 ms 852 KB Output is correct
77 Correct 12 ms 852 KB Output is correct
78 Correct 9 ms 860 KB Output is correct
79 Correct 10 ms 868 KB Output is correct
80 Correct 9 ms 868 KB Output is correct
81 Correct 16 ms 1472 KB Output is correct
82 Correct 24 ms 1548 KB Output is correct
83 Correct 22 ms 1488 KB Output is correct
84 Correct 24 ms 1468 KB Output is correct
85 Correct 18 ms 1540 KB Output is correct
86 Correct 20 ms 1932 KB Output is correct
87 Correct 22 ms 1876 KB Output is correct
88 Correct 18 ms 1856 KB Output is correct
89 Correct 24 ms 1872 KB Output is correct
90 Correct 20 ms 1928 KB Output is correct
91 Correct 29 ms 3916 KB Output is correct
92 Correct 37 ms 3912 KB Output is correct
93 Correct 26 ms 3904 KB Output is correct
94 Correct 29 ms 3916 KB Output is correct
95 Correct 29 ms 3976 KB Output is correct
96 Correct 37 ms 5952 KB Output is correct
97 Correct 44 ms 5972 KB Output is correct
98 Correct 48 ms 5932 KB Output is correct
99 Correct 42 ms 5960 KB Output is correct
100 Correct 41 ms 5936 KB Output is correct
101 Correct 37 ms 5960 KB Output is correct
102 Correct 43 ms 5960 KB Output is correct
103 Correct 38 ms 5944 KB Output is correct
104 Correct 43 ms 5952 KB Output is correct
105 Correct 35 ms 5960 KB Output is correct
106 Correct 36 ms 6344 KB Output is correct
107 Correct 56 ms 6344 KB Output is correct
108 Correct 35 ms 6356 KB Output is correct
109 Correct 37 ms 6348 KB Output is correct
110 Correct 45 ms 6340 KB Output is correct
111 Correct 36 ms 6344 KB Output is correct
112 Correct 37 ms 6352 KB Output is correct
113 Correct 39 ms 6384 KB Output is correct
114 Correct 32 ms 6364 KB Output is correct
115 Correct 32 ms 6364 KB Output is correct
116 Incorrect 2 ms 340 KB Output isn't correct
117 Halted 0 ms 0 KB -