Submission #931973

# Submission time Handle Problem Language Result Execution time Memory
931973 2024-02-22T16:58:20 Z sysia Diversity (CEOI21_diversity) C++17
64 / 100
189 ms 24548 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;

void solve(){
    int n, q; cin >> n >> q;
    vector<int>a(n+1);
    map<int, int>cnt;
    for (int i = 1; i<=n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    vector<int>curr;
    for (auto [aa, b]: cnt){
        curr.emplace_back(b);
    }
    sort(curr.begin(), curr.end());
    int m = (int)curr.size();
    int L = 0, R = m-1;
    vector<int>what(m);
    int ptr = 0;
    while (R >= L){
        what[L++] = curr[ptr++];
        if (R < L) break;
        what[R--] = curr[ptr++];
    }
    
    debug(curr);
    debug(what);
    int ans = 0;
    for (auto x: what) {
        ans += (x*(x+1))/2;
    }
    int s = 0, ilo = 0;
    for (int i = 0; i<m; i++){
        ans += (i+1) * s * what[i];
        ans -= what[i] * ilo;
        s += what[i];
        ilo += i*what[i];
    }
    cout << ans << "\n";
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Correct 10 ms 2396 KB Output is correct
6 Correct 19 ms 3444 KB Output is correct
7 Correct 15 ms 3420 KB Output is correct
8 Correct 20 ms 3420 KB Output is correct
9 Correct 15 ms 3420 KB Output is correct
10 Correct 15 ms 3316 KB Output is correct
11 Correct 20 ms 3312 KB Output is correct
12 Correct 16 ms 3444 KB Output is correct
13 Correct 15 ms 3416 KB Output is correct
14 Correct 16 ms 3420 KB Output is correct
15 Correct 16 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Correct 10 ms 2396 KB Output is correct
6 Correct 19 ms 3444 KB Output is correct
7 Correct 15 ms 3420 KB Output is correct
8 Correct 20 ms 3420 KB Output is correct
9 Correct 15 ms 3420 KB Output is correct
10 Correct 15 ms 3316 KB Output is correct
11 Correct 20 ms 3312 KB Output is correct
12 Correct 16 ms 3444 KB Output is correct
13 Correct 15 ms 3416 KB Output is correct
14 Correct 16 ms 3420 KB Output is correct
15 Correct 16 ms 3420 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 6 ms 1368 KB Output is correct
20 Correct 12 ms 2396 KB Output is correct
21 Correct 18 ms 3420 KB Output is correct
22 Correct 22 ms 3420 KB Output is correct
23 Correct 21 ms 3416 KB Output is correct
24 Correct 18 ms 3556 KB Output is correct
25 Correct 19 ms 3420 KB Output is correct
26 Correct 20 ms 3420 KB Output is correct
27 Correct 19 ms 3420 KB Output is correct
28 Correct 18 ms 3420 KB Output is correct
29 Correct 18 ms 3416 KB Output is correct
30 Correct 18 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Correct 10 ms 2396 KB Output is correct
6 Correct 19 ms 3444 KB Output is correct
7 Correct 15 ms 3420 KB Output is correct
8 Correct 20 ms 3420 KB Output is correct
9 Correct 15 ms 3420 KB Output is correct
10 Correct 15 ms 3316 KB Output is correct
11 Correct 20 ms 3312 KB Output is correct
12 Correct 16 ms 3444 KB Output is correct
13 Correct 15 ms 3416 KB Output is correct
14 Correct 16 ms 3420 KB Output is correct
15 Correct 16 ms 3420 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 6 ms 1368 KB Output is correct
20 Correct 12 ms 2396 KB Output is correct
21 Correct 18 ms 3420 KB Output is correct
22 Correct 22 ms 3420 KB Output is correct
23 Correct 21 ms 3416 KB Output is correct
24 Correct 18 ms 3556 KB Output is correct
25 Correct 19 ms 3420 KB Output is correct
26 Correct 20 ms 3420 KB Output is correct
27 Correct 19 ms 3420 KB Output is correct
28 Correct 18 ms 3420 KB Output is correct
29 Correct 18 ms 3416 KB Output is correct
30 Correct 18 ms 3420 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 452 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 5 ms 980 KB Output is correct
38 Correct 5 ms 1116 KB Output is correct
39 Correct 10 ms 1880 KB Output is correct
40 Correct 19 ms 2840 KB Output is correct
41 Correct 29 ms 3928 KB Output is correct
42 Correct 28 ms 3932 KB Output is correct
43 Correct 31 ms 3920 KB Output is correct
44 Correct 29 ms 4012 KB Output is correct
45 Correct 28 ms 3932 KB Output is correct
46 Correct 29 ms 3932 KB Output is correct
47 Correct 30 ms 3920 KB Output is correct
48 Correct 28 ms 3932 KB Output is correct
49 Correct 29 ms 3920 KB Output is correct
50 Correct 29 ms 3932 KB Output is correct
51 Correct 30 ms 4024 KB Output is correct
52 Correct 28 ms 3932 KB Output is correct
53 Correct 28 ms 3928 KB Output is correct
54 Correct 29 ms 4008 KB Output is correct
55 Correct 29 ms 3928 KB Output is correct
56 Correct 29 ms 3932 KB Output is correct
57 Correct 29 ms 4176 KB Output is correct
58 Correct 29 ms 3928 KB Output is correct
59 Correct 29 ms 4012 KB Output is correct
60 Correct 28 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1364 KB Output is correct
15 Correct 10 ms 2396 KB Output is correct
16 Correct 19 ms 3444 KB Output is correct
17 Correct 15 ms 3420 KB Output is correct
18 Correct 20 ms 3420 KB Output is correct
19 Correct 15 ms 3420 KB Output is correct
20 Correct 15 ms 3316 KB Output is correct
21 Correct 20 ms 3312 KB Output is correct
22 Correct 16 ms 3444 KB Output is correct
23 Correct 15 ms 3416 KB Output is correct
24 Correct 16 ms 3420 KB Output is correct
25 Correct 16 ms 3420 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 6 ms 1368 KB Output is correct
30 Correct 12 ms 2396 KB Output is correct
31 Correct 18 ms 3420 KB Output is correct
32 Correct 22 ms 3420 KB Output is correct
33 Correct 21 ms 3416 KB Output is correct
34 Correct 18 ms 3556 KB Output is correct
35 Correct 19 ms 3420 KB Output is correct
36 Correct 20 ms 3420 KB Output is correct
37 Correct 19 ms 3420 KB Output is correct
38 Correct 18 ms 3420 KB Output is correct
39 Correct 18 ms 3416 KB Output is correct
40 Correct 18 ms 3420 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 452 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 5 ms 980 KB Output is correct
48 Correct 5 ms 1116 KB Output is correct
49 Correct 10 ms 1880 KB Output is correct
50 Correct 19 ms 2840 KB Output is correct
51 Correct 29 ms 3928 KB Output is correct
52 Correct 28 ms 3932 KB Output is correct
53 Correct 31 ms 3920 KB Output is correct
54 Correct 29 ms 4012 KB Output is correct
55 Correct 28 ms 3932 KB Output is correct
56 Correct 29 ms 3932 KB Output is correct
57 Correct 30 ms 3920 KB Output is correct
58 Correct 28 ms 3932 KB Output is correct
59 Correct 29 ms 3920 KB Output is correct
60 Correct 29 ms 3932 KB Output is correct
61 Correct 30 ms 4024 KB Output is correct
62 Correct 28 ms 3932 KB Output is correct
63 Correct 28 ms 3928 KB Output is correct
64 Correct 29 ms 4008 KB Output is correct
65 Correct 29 ms 3928 KB Output is correct
66 Correct 29 ms 3932 KB Output is correct
67 Correct 29 ms 4176 KB Output is correct
68 Correct 29 ms 3928 KB Output is correct
69 Correct 29 ms 4012 KB Output is correct
70 Correct 28 ms 3924 KB Output is correct
71 Correct 6 ms 1052 KB Output is correct
72 Correct 6 ms 1116 KB Output is correct
73 Correct 6 ms 1116 KB Output is correct
74 Correct 6 ms 1112 KB Output is correct
75 Correct 6 ms 1116 KB Output is correct
76 Correct 14 ms 2140 KB Output is correct
77 Correct 14 ms 2128 KB Output is correct
78 Correct 14 ms 1884 KB Output is correct
79 Correct 14 ms 2020 KB Output is correct
80 Correct 14 ms 2140 KB Output is correct
81 Correct 32 ms 3740 KB Output is correct
82 Correct 31 ms 3668 KB Output is correct
83 Correct 31 ms 3640 KB Output is correct
84 Correct 32 ms 3664 KB Output is correct
85 Correct 34 ms 3756 KB Output is correct
86 Correct 39 ms 4688 KB Output is correct
87 Correct 38 ms 4620 KB Output is correct
88 Correct 44 ms 4700 KB Output is correct
89 Correct 39 ms 4692 KB Output is correct
90 Correct 39 ms 4724 KB Output is correct
91 Correct 86 ms 12296 KB Output is correct
92 Correct 84 ms 12484 KB Output is correct
93 Correct 85 ms 12232 KB Output is correct
94 Correct 83 ms 12484 KB Output is correct
95 Correct 83 ms 12456 KB Output is correct
96 Correct 143 ms 20392 KB Output is correct
97 Correct 117 ms 20400 KB Output is correct
98 Correct 149 ms 20360 KB Output is correct
99 Correct 137 ms 20572 KB Output is correct
100 Correct 143 ms 20420 KB Output is correct
101 Correct 123 ms 20712 KB Output is correct
102 Correct 120 ms 20420 KB Output is correct
103 Correct 137 ms 20572 KB Output is correct
104 Correct 114 ms 20288 KB Output is correct
105 Correct 127 ms 20412 KB Output is correct
106 Correct 158 ms 24320 KB Output is correct
107 Correct 147 ms 24548 KB Output is correct
108 Correct 163 ms 24296 KB Output is correct
109 Correct 144 ms 24384 KB Output is correct
110 Correct 189 ms 24436 KB Output is correct
111 Correct 163 ms 24260 KB Output is correct
112 Correct 149 ms 24268 KB Output is correct
113 Correct 164 ms 24288 KB Output is correct
114 Correct 157 ms 24216 KB Output is correct
115 Correct 159 ms 24432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 1364 KB Output is correct
15 Correct 10 ms 2396 KB Output is correct
16 Correct 19 ms 3444 KB Output is correct
17 Correct 15 ms 3420 KB Output is correct
18 Correct 20 ms 3420 KB Output is correct
19 Correct 15 ms 3420 KB Output is correct
20 Correct 15 ms 3316 KB Output is correct
21 Correct 20 ms 3312 KB Output is correct
22 Correct 16 ms 3444 KB Output is correct
23 Correct 15 ms 3416 KB Output is correct
24 Correct 16 ms 3420 KB Output is correct
25 Correct 16 ms 3420 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 6 ms 1368 KB Output is correct
30 Correct 12 ms 2396 KB Output is correct
31 Correct 18 ms 3420 KB Output is correct
32 Correct 22 ms 3420 KB Output is correct
33 Correct 21 ms 3416 KB Output is correct
34 Correct 18 ms 3556 KB Output is correct
35 Correct 19 ms 3420 KB Output is correct
36 Correct 20 ms 3420 KB Output is correct
37 Correct 19 ms 3420 KB Output is correct
38 Correct 18 ms 3420 KB Output is correct
39 Correct 18 ms 3416 KB Output is correct
40 Correct 18 ms 3420 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 452 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 5 ms 980 KB Output is correct
48 Correct 5 ms 1116 KB Output is correct
49 Correct 10 ms 1880 KB Output is correct
50 Correct 19 ms 2840 KB Output is correct
51 Correct 29 ms 3928 KB Output is correct
52 Correct 28 ms 3932 KB Output is correct
53 Correct 31 ms 3920 KB Output is correct
54 Correct 29 ms 4012 KB Output is correct
55 Correct 28 ms 3932 KB Output is correct
56 Correct 29 ms 3932 KB Output is correct
57 Correct 30 ms 3920 KB Output is correct
58 Correct 28 ms 3932 KB Output is correct
59 Correct 29 ms 3920 KB Output is correct
60 Correct 29 ms 3932 KB Output is correct
61 Correct 30 ms 4024 KB Output is correct
62 Correct 28 ms 3932 KB Output is correct
63 Correct 28 ms 3928 KB Output is correct
64 Correct 29 ms 4008 KB Output is correct
65 Correct 29 ms 3928 KB Output is correct
66 Correct 29 ms 3932 KB Output is correct
67 Correct 29 ms 4176 KB Output is correct
68 Correct 29 ms 3928 KB Output is correct
69 Correct 29 ms 4012 KB Output is correct
70 Correct 28 ms 3924 KB Output is correct
71 Correct 6 ms 1052 KB Output is correct
72 Correct 6 ms 1116 KB Output is correct
73 Correct 6 ms 1116 KB Output is correct
74 Correct 6 ms 1112 KB Output is correct
75 Correct 6 ms 1116 KB Output is correct
76 Correct 14 ms 2140 KB Output is correct
77 Correct 14 ms 2128 KB Output is correct
78 Correct 14 ms 1884 KB Output is correct
79 Correct 14 ms 2020 KB Output is correct
80 Correct 14 ms 2140 KB Output is correct
81 Correct 32 ms 3740 KB Output is correct
82 Correct 31 ms 3668 KB Output is correct
83 Correct 31 ms 3640 KB Output is correct
84 Correct 32 ms 3664 KB Output is correct
85 Correct 34 ms 3756 KB Output is correct
86 Correct 39 ms 4688 KB Output is correct
87 Correct 38 ms 4620 KB Output is correct
88 Correct 44 ms 4700 KB Output is correct
89 Correct 39 ms 4692 KB Output is correct
90 Correct 39 ms 4724 KB Output is correct
91 Correct 86 ms 12296 KB Output is correct
92 Correct 84 ms 12484 KB Output is correct
93 Correct 85 ms 12232 KB Output is correct
94 Correct 83 ms 12484 KB Output is correct
95 Correct 83 ms 12456 KB Output is correct
96 Correct 143 ms 20392 KB Output is correct
97 Correct 117 ms 20400 KB Output is correct
98 Correct 149 ms 20360 KB Output is correct
99 Correct 137 ms 20572 KB Output is correct
100 Correct 143 ms 20420 KB Output is correct
101 Correct 123 ms 20712 KB Output is correct
102 Correct 120 ms 20420 KB Output is correct
103 Correct 137 ms 20572 KB Output is correct
104 Correct 114 ms 20288 KB Output is correct
105 Correct 127 ms 20412 KB Output is correct
106 Correct 158 ms 24320 KB Output is correct
107 Correct 147 ms 24548 KB Output is correct
108 Correct 163 ms 24296 KB Output is correct
109 Correct 144 ms 24384 KB Output is correct
110 Correct 189 ms 24436 KB Output is correct
111 Correct 163 ms 24260 KB Output is correct
112 Correct 149 ms 24268 KB Output is correct
113 Correct 164 ms 24288 KB Output is correct
114 Correct 157 ms 24216 KB Output is correct
115 Correct 159 ms 24432 KB Output is correct
116 Incorrect 1 ms 604 KB Output isn't correct
117 Halted 0 ms 0 KB -