Submission #988798

# Submission time Handle Problem Language Result Execution time Memory
988798 2024-05-26T08:21:38 Z LOLOLO Diversity (CEOI21_diversity) C++17
64 / 100
27 ms 7376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 10;
int cnt[N];

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

    int n, q;
    cin >> n >> q;

    assert(q == 1);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    vector <ll> val;
    for (int i = 1; i < N; i++) {
        if (cnt[i])
            val.pb(cnt[i]);
    }

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

    sort(all(val), greater <ll> ());
    deque <ll> dq;
    int odd = 0;
    ll ans = 0;

    for (auto x : val) {
        if (odd == 0) {
            dq.pb(x);
        } else {
            dq.push_front(x);
        }

        odd = 1 - odd;
        ans += x * (x + 1) / 2;
    } 

    ll sum = 0, nor = 0;
    while (sz(dq)) {
        ll t = dq.front();
        dq.pop_front();
        sum += nor;
        ans += (t * sum);
        nor += t;
        sum += t;
    }

    cout << ans << '\n';
    return 0;
} 

// (n + ) * n 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 7 ms 828 KB Output is correct
6 Correct 11 ms 1116 KB Output is correct
7 Correct 10 ms 960 KB Output is correct
8 Correct 10 ms 1088 KB Output is correct
9 Correct 10 ms 860 KB Output is correct
10 Correct 11 ms 1116 KB Output is correct
11 Correct 11 ms 1104 KB Output is correct
12 Correct 11 ms 1092 KB Output is correct
13 Correct 11 ms 860 KB Output is correct
14 Correct 11 ms 856 KB Output is correct
15 Correct 10 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 7 ms 828 KB Output is correct
6 Correct 11 ms 1116 KB Output is correct
7 Correct 10 ms 960 KB Output is correct
8 Correct 10 ms 1088 KB Output is correct
9 Correct 10 ms 860 KB Output is correct
10 Correct 11 ms 1116 KB Output is correct
11 Correct 11 ms 1104 KB Output is correct
12 Correct 11 ms 1092 KB Output is correct
13 Correct 11 ms 860 KB Output is correct
14 Correct 11 ms 856 KB Output is correct
15 Correct 10 ms 1092 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 5 ms 572 KB Output is correct
20 Correct 8 ms 860 KB Output is correct
21 Correct 11 ms 1116 KB Output is correct
22 Correct 12 ms 1116 KB Output is correct
23 Correct 11 ms 1088 KB Output is correct
24 Correct 12 ms 1116 KB Output is correct
25 Correct 12 ms 1116 KB Output is correct
26 Correct 12 ms 1116 KB Output is correct
27 Correct 12 ms 1116 KB Output is correct
28 Correct 12 ms 960 KB Output is correct
29 Correct 12 ms 1088 KB Output is correct
30 Correct 11 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 7 ms 828 KB Output is correct
6 Correct 11 ms 1116 KB Output is correct
7 Correct 10 ms 960 KB Output is correct
8 Correct 10 ms 1088 KB Output is correct
9 Correct 10 ms 860 KB Output is correct
10 Correct 11 ms 1116 KB Output is correct
11 Correct 11 ms 1104 KB Output is correct
12 Correct 11 ms 1092 KB Output is correct
13 Correct 11 ms 860 KB Output is correct
14 Correct 11 ms 856 KB Output is correct
15 Correct 10 ms 1092 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 5 ms 572 KB Output is correct
20 Correct 8 ms 860 KB Output is correct
21 Correct 11 ms 1116 KB Output is correct
22 Correct 12 ms 1116 KB Output is correct
23 Correct 11 ms 1088 KB Output is correct
24 Correct 12 ms 1116 KB Output is correct
25 Correct 12 ms 1116 KB Output is correct
26 Correct 12 ms 1116 KB Output is correct
27 Correct 12 ms 1116 KB Output is correct
28 Correct 12 ms 960 KB Output is correct
29 Correct 12 ms 1088 KB Output is correct
30 Correct 11 ms 1116 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 3 ms 652 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 5 ms 860 KB Output is correct
40 Correct 8 ms 1116 KB Output is correct
41 Correct 13 ms 1604 KB Output is correct
42 Correct 12 ms 1624 KB Output is correct
43 Correct 13 ms 1628 KB Output is correct
44 Correct 13 ms 1880 KB Output is correct
45 Correct 14 ms 1604 KB Output is correct
46 Correct 12 ms 1628 KB Output is correct
47 Correct 12 ms 1624 KB Output is correct
48 Correct 13 ms 1476 KB Output is correct
49 Correct 13 ms 1600 KB Output is correct
50 Correct 13 ms 1628 KB Output is correct
51 Correct 12 ms 1628 KB Output is correct
52 Correct 17 ms 1600 KB Output is correct
53 Correct 12 ms 1604 KB Output is correct
54 Correct 12 ms 1476 KB Output is correct
55 Correct 12 ms 1628 KB Output is correct
56 Correct 12 ms 1604 KB Output is correct
57 Correct 12 ms 1604 KB Output is correct
58 Correct 12 ms 1628 KB Output is correct
59 Correct 12 ms 1620 KB Output is correct
60 Correct 12 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 7 ms 828 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 10 ms 960 KB Output is correct
18 Correct 10 ms 1088 KB Output is correct
19 Correct 10 ms 860 KB Output is correct
20 Correct 11 ms 1116 KB Output is correct
21 Correct 11 ms 1104 KB Output is correct
22 Correct 11 ms 1092 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 11 ms 856 KB Output is correct
25 Correct 10 ms 1092 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 5 ms 572 KB Output is correct
30 Correct 8 ms 860 KB Output is correct
31 Correct 11 ms 1116 KB Output is correct
32 Correct 12 ms 1116 KB Output is correct
33 Correct 11 ms 1088 KB Output is correct
34 Correct 12 ms 1116 KB Output is correct
35 Correct 12 ms 1116 KB Output is correct
36 Correct 12 ms 1116 KB Output is correct
37 Correct 12 ms 1116 KB Output is correct
38 Correct 12 ms 960 KB Output is correct
39 Correct 12 ms 1088 KB Output is correct
40 Correct 11 ms 1116 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 652 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 5 ms 860 KB Output is correct
50 Correct 8 ms 1116 KB Output is correct
51 Correct 13 ms 1604 KB Output is correct
52 Correct 12 ms 1624 KB Output is correct
53 Correct 13 ms 1628 KB Output is correct
54 Correct 13 ms 1880 KB Output is correct
55 Correct 14 ms 1604 KB Output is correct
56 Correct 12 ms 1628 KB Output is correct
57 Correct 12 ms 1624 KB Output is correct
58 Correct 13 ms 1476 KB Output is correct
59 Correct 13 ms 1600 KB Output is correct
60 Correct 13 ms 1628 KB Output is correct
61 Correct 12 ms 1628 KB Output is correct
62 Correct 17 ms 1600 KB Output is correct
63 Correct 12 ms 1604 KB Output is correct
64 Correct 12 ms 1476 KB Output is correct
65 Correct 12 ms 1628 KB Output is correct
66 Correct 12 ms 1604 KB Output is correct
67 Correct 12 ms 1604 KB Output is correct
68 Correct 12 ms 1628 KB Output is correct
69 Correct 12 ms 1620 KB Output is correct
70 Correct 12 ms 1372 KB Output is correct
71 Correct 3 ms 604 KB Output is correct
72 Correct 3 ms 580 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 3 ms 604 KB Output is correct
75 Correct 3 ms 604 KB Output is correct
76 Correct 5 ms 856 KB Output is correct
77 Correct 6 ms 860 KB Output is correct
78 Correct 5 ms 948 KB Output is correct
79 Correct 5 ms 860 KB Output is correct
80 Correct 6 ms 860 KB Output is correct
81 Correct 10 ms 1640 KB Output is correct
82 Correct 10 ms 1628 KB Output is correct
83 Correct 11 ms 1628 KB Output is correct
84 Correct 10 ms 1516 KB Output is correct
85 Correct 10 ms 1624 KB Output is correct
86 Correct 12 ms 1884 KB Output is correct
87 Correct 12 ms 1936 KB Output is correct
88 Correct 11 ms 1884 KB Output is correct
89 Correct 12 ms 1932 KB Output is correct
90 Correct 11 ms 1928 KB Output is correct
91 Correct 19 ms 4056 KB Output is correct
92 Correct 20 ms 4056 KB Output is correct
93 Correct 19 ms 4016 KB Output is correct
94 Correct 19 ms 4056 KB Output is correct
95 Correct 19 ms 4032 KB Output is correct
96 Correct 24 ms 6320 KB Output is correct
97 Correct 25 ms 6120 KB Output is correct
98 Correct 24 ms 6316 KB Output is correct
99 Correct 24 ms 6356 KB Output is correct
100 Correct 24 ms 6332 KB Output is correct
101 Correct 26 ms 6336 KB Output is correct
102 Correct 24 ms 6352 KB Output is correct
103 Correct 24 ms 6356 KB Output is correct
104 Correct 24 ms 6356 KB Output is correct
105 Correct 25 ms 6252 KB Output is correct
106 Correct 25 ms 7304 KB Output is correct
107 Correct 27 ms 7172 KB Output is correct
108 Correct 25 ms 7376 KB Output is correct
109 Correct 25 ms 7372 KB Output is correct
110 Correct 25 ms 7300 KB Output is correct
111 Correct 24 ms 7372 KB Output is correct
112 Correct 24 ms 7368 KB Output is correct
113 Correct 27 ms 7368 KB Output is correct
114 Correct 26 ms 7180 KB Output is correct
115 Correct 25 ms 7308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 7 ms 828 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 10 ms 960 KB Output is correct
18 Correct 10 ms 1088 KB Output is correct
19 Correct 10 ms 860 KB Output is correct
20 Correct 11 ms 1116 KB Output is correct
21 Correct 11 ms 1104 KB Output is correct
22 Correct 11 ms 1092 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 11 ms 856 KB Output is correct
25 Correct 10 ms 1092 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 5 ms 572 KB Output is correct
30 Correct 8 ms 860 KB Output is correct
31 Correct 11 ms 1116 KB Output is correct
32 Correct 12 ms 1116 KB Output is correct
33 Correct 11 ms 1088 KB Output is correct
34 Correct 12 ms 1116 KB Output is correct
35 Correct 12 ms 1116 KB Output is correct
36 Correct 12 ms 1116 KB Output is correct
37 Correct 12 ms 1116 KB Output is correct
38 Correct 12 ms 960 KB Output is correct
39 Correct 12 ms 1088 KB Output is correct
40 Correct 11 ms 1116 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 652 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 5 ms 860 KB Output is correct
50 Correct 8 ms 1116 KB Output is correct
51 Correct 13 ms 1604 KB Output is correct
52 Correct 12 ms 1624 KB Output is correct
53 Correct 13 ms 1628 KB Output is correct
54 Correct 13 ms 1880 KB Output is correct
55 Correct 14 ms 1604 KB Output is correct
56 Correct 12 ms 1628 KB Output is correct
57 Correct 12 ms 1624 KB Output is correct
58 Correct 13 ms 1476 KB Output is correct
59 Correct 13 ms 1600 KB Output is correct
60 Correct 13 ms 1628 KB Output is correct
61 Correct 12 ms 1628 KB Output is correct
62 Correct 17 ms 1600 KB Output is correct
63 Correct 12 ms 1604 KB Output is correct
64 Correct 12 ms 1476 KB Output is correct
65 Correct 12 ms 1628 KB Output is correct
66 Correct 12 ms 1604 KB Output is correct
67 Correct 12 ms 1604 KB Output is correct
68 Correct 12 ms 1628 KB Output is correct
69 Correct 12 ms 1620 KB Output is correct
70 Correct 12 ms 1372 KB Output is correct
71 Correct 3 ms 604 KB Output is correct
72 Correct 3 ms 580 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 3 ms 604 KB Output is correct
75 Correct 3 ms 604 KB Output is correct
76 Correct 5 ms 856 KB Output is correct
77 Correct 6 ms 860 KB Output is correct
78 Correct 5 ms 948 KB Output is correct
79 Correct 5 ms 860 KB Output is correct
80 Correct 6 ms 860 KB Output is correct
81 Correct 10 ms 1640 KB Output is correct
82 Correct 10 ms 1628 KB Output is correct
83 Correct 11 ms 1628 KB Output is correct
84 Correct 10 ms 1516 KB Output is correct
85 Correct 10 ms 1624 KB Output is correct
86 Correct 12 ms 1884 KB Output is correct
87 Correct 12 ms 1936 KB Output is correct
88 Correct 11 ms 1884 KB Output is correct
89 Correct 12 ms 1932 KB Output is correct
90 Correct 11 ms 1928 KB Output is correct
91 Correct 19 ms 4056 KB Output is correct
92 Correct 20 ms 4056 KB Output is correct
93 Correct 19 ms 4016 KB Output is correct
94 Correct 19 ms 4056 KB Output is correct
95 Correct 19 ms 4032 KB Output is correct
96 Correct 24 ms 6320 KB Output is correct
97 Correct 25 ms 6120 KB Output is correct
98 Correct 24 ms 6316 KB Output is correct
99 Correct 24 ms 6356 KB Output is correct
100 Correct 24 ms 6332 KB Output is correct
101 Correct 26 ms 6336 KB Output is correct
102 Correct 24 ms 6352 KB Output is correct
103 Correct 24 ms 6356 KB Output is correct
104 Correct 24 ms 6356 KB Output is correct
105 Correct 25 ms 6252 KB Output is correct
106 Correct 25 ms 7304 KB Output is correct
107 Correct 27 ms 7172 KB Output is correct
108 Correct 25 ms 7376 KB Output is correct
109 Correct 25 ms 7372 KB Output is correct
110 Correct 25 ms 7300 KB Output is correct
111 Correct 24 ms 7372 KB Output is correct
112 Correct 24 ms 7368 KB Output is correct
113 Correct 27 ms 7368 KB Output is correct
114 Correct 26 ms 7180 KB Output is correct
115 Correct 25 ms 7308 KB Output is correct
116 Runtime error 1 ms 604 KB Execution killed with signal 6
117 Halted 0 ms 0 KB -