답안 #1114594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114594 2024-11-19T08:26:32 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
41 ms 14408 KB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

constexpr int max_A = int(3E5) + 5;

int cnt[max_A];

i64 calc_slow(std::vector<i64> x) {
    int n = int(x.size());
    i64 ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += x[i] * (x[i] + 1) / 2;
        i64 s = 0;
        for (int j = i + 1; j < n; ++j) {
            s += x[j] * (j - i + 1);
        }
        debug(i, s);
        ans += x[i] * s;
    }
    return ans;
}

i64 calc(std::vector<i64> x) {
    int n = int(x.size());
    i64 ans = 0;
    std::vector<i64> sum(n + 1), f(n + 1);
    for (int i = n - 1; i >= 0; --i) {
        sum[i] = sum[i + 1] + x[i];
    }
    for (int i = n - 1; i >= 0; --i) {
        f[i] = f[i + 1] + sum[i];
    }
    debug(sum, f);
    for (int i = 0; i < n; ++i) {
        ans += x[i] * (x[i] + 1) / 2;
        debug(i, f[i + 1] + sum[i + 1]);
        ans += x[i] * (f[i + 1] + sum[i + 1]);
    }
    return ans;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N, Q;
    std::cin >> N >> Q;
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    std::vector<int> L(Q), R(Q);
    for (int i = 0; i < Q; ++i) {
        std::cin >> L[i] >> R[i];
    }

    for (int i = 0; i < N; ++i) {
        ++cnt[A[i]];
    }

    std::vector<i64> x;
    for (int i = 0; i < max_A; ++i) {
        if (cnt[i] != 0) {
            x.emplace_back(cnt[i]);
        }
    }

    int n = int(x.size());

    std::sort(x.begin(), x.end());

    std::vector<i64> w(n);
    int l = 0, r = n - 1;
    for (int i = 0; i < n; ++i) {
        if (~i & 1) w[l++] = x[i];
        else w[r--] = x[i];
    }

    debug(w);

    i64 ans = calc(w);
    debug(calc_slow(w));
    std::cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 5 ms 848 KB Output is correct
5 Correct 9 ms 1104 KB Output is correct
6 Correct 14 ms 1616 KB Output is correct
7 Correct 12 ms 1616 KB Output is correct
8 Correct 14 ms 1616 KB Output is correct
9 Correct 13 ms 1616 KB Output is correct
10 Correct 14 ms 1616 KB Output is correct
11 Correct 13 ms 1616 KB Output is correct
12 Correct 14 ms 1616 KB Output is correct
13 Correct 13 ms 1616 KB Output is correct
14 Correct 14 ms 1616 KB Output is correct
15 Correct 12 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 5 ms 848 KB Output is correct
5 Correct 9 ms 1104 KB Output is correct
6 Correct 14 ms 1616 KB Output is correct
7 Correct 12 ms 1616 KB Output is correct
8 Correct 14 ms 1616 KB Output is correct
9 Correct 13 ms 1616 KB Output is correct
10 Correct 14 ms 1616 KB Output is correct
11 Correct 13 ms 1616 KB Output is correct
12 Correct 14 ms 1616 KB Output is correct
13 Correct 13 ms 1616 KB Output is correct
14 Correct 14 ms 1616 KB Output is correct
15 Correct 12 ms 1616 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 5 ms 848 KB Output is correct
20 Correct 10 ms 1104 KB Output is correct
21 Correct 13 ms 1616 KB Output is correct
22 Correct 14 ms 1616 KB Output is correct
23 Correct 14 ms 1616 KB Output is correct
24 Correct 15 ms 1616 KB Output is correct
25 Correct 15 ms 1616 KB Output is correct
26 Correct 14 ms 1784 KB Output is correct
27 Correct 14 ms 1616 KB Output is correct
28 Correct 14 ms 1616 KB Output is correct
29 Correct 15 ms 1616 KB Output is correct
30 Correct 15 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 5 ms 848 KB Output is correct
5 Correct 9 ms 1104 KB Output is correct
6 Correct 14 ms 1616 KB Output is correct
7 Correct 12 ms 1616 KB Output is correct
8 Correct 14 ms 1616 KB Output is correct
9 Correct 13 ms 1616 KB Output is correct
10 Correct 14 ms 1616 KB Output is correct
11 Correct 13 ms 1616 KB Output is correct
12 Correct 14 ms 1616 KB Output is correct
13 Correct 13 ms 1616 KB Output is correct
14 Correct 14 ms 1616 KB Output is correct
15 Correct 12 ms 1616 KB Output is correct
16 Correct 1 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 5 ms 848 KB Output is correct
20 Correct 10 ms 1104 KB Output is correct
21 Correct 13 ms 1616 KB Output is correct
22 Correct 14 ms 1616 KB Output is correct
23 Correct 14 ms 1616 KB Output is correct
24 Correct 15 ms 1616 KB Output is correct
25 Correct 15 ms 1616 KB Output is correct
26 Correct 14 ms 1784 KB Output is correct
27 Correct 14 ms 1616 KB Output is correct
28 Correct 14 ms 1616 KB Output is correct
29 Correct 15 ms 1616 KB Output is correct
30 Correct 15 ms 1616 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 476 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 4 ms 592 KB Output is correct
38 Correct 4 ms 592 KB Output is correct
39 Correct 7 ms 848 KB Output is correct
40 Correct 10 ms 1256 KB Output is correct
41 Correct 16 ms 1616 KB Output is correct
42 Correct 15 ms 1784 KB Output is correct
43 Correct 13 ms 1616 KB Output is correct
44 Correct 14 ms 1616 KB Output is correct
45 Correct 15 ms 1784 KB Output is correct
46 Correct 16 ms 1616 KB Output is correct
47 Correct 15 ms 1616 KB Output is correct
48 Correct 16 ms 1616 KB Output is correct
49 Correct 16 ms 1616 KB Output is correct
50 Correct 16 ms 1616 KB Output is correct
51 Correct 15 ms 1616 KB Output is correct
52 Correct 14 ms 1616 KB Output is correct
53 Correct 15 ms 1640 KB Output is correct
54 Correct 15 ms 1616 KB Output is correct
55 Correct 15 ms 1616 KB Output is correct
56 Correct 14 ms 1616 KB Output is correct
57 Correct 15 ms 1644 KB Output is correct
58 Correct 14 ms 1616 KB Output is correct
59 Correct 14 ms 1636 KB Output is correct
60 Correct 15 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 5 ms 848 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 14 ms 1616 KB Output is correct
17 Correct 12 ms 1616 KB Output is correct
18 Correct 14 ms 1616 KB Output is correct
19 Correct 13 ms 1616 KB Output is correct
20 Correct 14 ms 1616 KB Output is correct
21 Correct 13 ms 1616 KB Output is correct
22 Correct 14 ms 1616 KB Output is correct
23 Correct 13 ms 1616 KB Output is correct
24 Correct 14 ms 1616 KB Output is correct
25 Correct 12 ms 1616 KB Output is correct
26 Correct 1 ms 504 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 5 ms 848 KB Output is correct
30 Correct 10 ms 1104 KB Output is correct
31 Correct 13 ms 1616 KB Output is correct
32 Correct 14 ms 1616 KB Output is correct
33 Correct 14 ms 1616 KB Output is correct
34 Correct 15 ms 1616 KB Output is correct
35 Correct 15 ms 1616 KB Output is correct
36 Correct 14 ms 1784 KB Output is correct
37 Correct 14 ms 1616 KB Output is correct
38 Correct 14 ms 1616 KB Output is correct
39 Correct 15 ms 1616 KB Output is correct
40 Correct 15 ms 1616 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 476 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 2 ms 336 KB Output is correct
45 Correct 2 ms 336 KB Output is correct
46 Correct 2 ms 336 KB Output is correct
47 Correct 4 ms 592 KB Output is correct
48 Correct 4 ms 592 KB Output is correct
49 Correct 7 ms 848 KB Output is correct
50 Correct 10 ms 1256 KB Output is correct
51 Correct 16 ms 1616 KB Output is correct
52 Correct 15 ms 1784 KB Output is correct
53 Correct 13 ms 1616 KB Output is correct
54 Correct 14 ms 1616 KB Output is correct
55 Correct 15 ms 1784 KB Output is correct
56 Correct 16 ms 1616 KB Output is correct
57 Correct 15 ms 1616 KB Output is correct
58 Correct 16 ms 1616 KB Output is correct
59 Correct 16 ms 1616 KB Output is correct
60 Correct 16 ms 1616 KB Output is correct
61 Correct 15 ms 1616 KB Output is correct
62 Correct 14 ms 1616 KB Output is correct
63 Correct 15 ms 1640 KB Output is correct
64 Correct 15 ms 1616 KB Output is correct
65 Correct 15 ms 1616 KB Output is correct
66 Correct 14 ms 1616 KB Output is correct
67 Correct 15 ms 1644 KB Output is correct
68 Correct 14 ms 1616 KB Output is correct
69 Correct 14 ms 1636 KB Output is correct
70 Correct 15 ms 1616 KB Output is correct
71 Correct 4 ms 592 KB Output is correct
72 Correct 4 ms 592 KB Output is correct
73 Correct 4 ms 592 KB Output is correct
74 Correct 4 ms 592 KB Output is correct
75 Correct 4 ms 592 KB Output is correct
76 Correct 7 ms 1016 KB Output is correct
77 Correct 7 ms 848 KB Output is correct
78 Correct 7 ms 1104 KB Output is correct
79 Correct 7 ms 860 KB Output is correct
80 Correct 7 ms 848 KB Output is correct
81 Correct 12 ms 1616 KB Output is correct
82 Correct 11 ms 1616 KB Output is correct
83 Correct 11 ms 1616 KB Output is correct
84 Correct 12 ms 1616 KB Output is correct
85 Correct 11 ms 1616 KB Output is correct
86 Correct 14 ms 2260 KB Output is correct
87 Correct 13 ms 2260 KB Output is correct
88 Correct 16 ms 2004 KB Output is correct
89 Correct 14 ms 2152 KB Output is correct
90 Correct 13 ms 2260 KB Output is correct
91 Correct 24 ms 5860 KB Output is correct
92 Correct 23 ms 6092 KB Output is correct
93 Correct 23 ms 6012 KB Output is correct
94 Correct 24 ms 6260 KB Output is correct
95 Correct 23 ms 5836 KB Output is correct
96 Correct 29 ms 10688 KB Output is correct
97 Correct 33 ms 12480 KB Output is correct
98 Correct 37 ms 12104 KB Output is correct
99 Correct 41 ms 12492 KB Output is correct
100 Correct 30 ms 10688 KB Output is correct
101 Correct 32 ms 11968 KB Output is correct
102 Correct 31 ms 12448 KB Output is correct
103 Correct 30 ms 11968 KB Output is correct
104 Correct 31 ms 12024 KB Output is correct
105 Correct 29 ms 10688 KB Output is correct
106 Correct 39 ms 14408 KB Output is correct
107 Correct 31 ms 14272 KB Output is correct
108 Correct 30 ms 12480 KB Output is correct
109 Correct 37 ms 14280 KB Output is correct
110 Correct 31 ms 12488 KB Output is correct
111 Correct 38 ms 13760 KB Output is correct
112 Correct 32 ms 12488 KB Output is correct
113 Correct 33 ms 13760 KB Output is correct
114 Correct 39 ms 13760 KB Output is correct
115 Correct 31 ms 12480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 5 ms 848 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 14 ms 1616 KB Output is correct
17 Correct 12 ms 1616 KB Output is correct
18 Correct 14 ms 1616 KB Output is correct
19 Correct 13 ms 1616 KB Output is correct
20 Correct 14 ms 1616 KB Output is correct
21 Correct 13 ms 1616 KB Output is correct
22 Correct 14 ms 1616 KB Output is correct
23 Correct 13 ms 1616 KB Output is correct
24 Correct 14 ms 1616 KB Output is correct
25 Correct 12 ms 1616 KB Output is correct
26 Correct 1 ms 504 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 5 ms 848 KB Output is correct
30 Correct 10 ms 1104 KB Output is correct
31 Correct 13 ms 1616 KB Output is correct
32 Correct 14 ms 1616 KB Output is correct
33 Correct 14 ms 1616 KB Output is correct
34 Correct 15 ms 1616 KB Output is correct
35 Correct 15 ms 1616 KB Output is correct
36 Correct 14 ms 1784 KB Output is correct
37 Correct 14 ms 1616 KB Output is correct
38 Correct 14 ms 1616 KB Output is correct
39 Correct 15 ms 1616 KB Output is correct
40 Correct 15 ms 1616 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 476 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 2 ms 336 KB Output is correct
45 Correct 2 ms 336 KB Output is correct
46 Correct 2 ms 336 KB Output is correct
47 Correct 4 ms 592 KB Output is correct
48 Correct 4 ms 592 KB Output is correct
49 Correct 7 ms 848 KB Output is correct
50 Correct 10 ms 1256 KB Output is correct
51 Correct 16 ms 1616 KB Output is correct
52 Correct 15 ms 1784 KB Output is correct
53 Correct 13 ms 1616 KB Output is correct
54 Correct 14 ms 1616 KB Output is correct
55 Correct 15 ms 1784 KB Output is correct
56 Correct 16 ms 1616 KB Output is correct
57 Correct 15 ms 1616 KB Output is correct
58 Correct 16 ms 1616 KB Output is correct
59 Correct 16 ms 1616 KB Output is correct
60 Correct 16 ms 1616 KB Output is correct
61 Correct 15 ms 1616 KB Output is correct
62 Correct 14 ms 1616 KB Output is correct
63 Correct 15 ms 1640 KB Output is correct
64 Correct 15 ms 1616 KB Output is correct
65 Correct 15 ms 1616 KB Output is correct
66 Correct 14 ms 1616 KB Output is correct
67 Correct 15 ms 1644 KB Output is correct
68 Correct 14 ms 1616 KB Output is correct
69 Correct 14 ms 1636 KB Output is correct
70 Correct 15 ms 1616 KB Output is correct
71 Correct 4 ms 592 KB Output is correct
72 Correct 4 ms 592 KB Output is correct
73 Correct 4 ms 592 KB Output is correct
74 Correct 4 ms 592 KB Output is correct
75 Correct 4 ms 592 KB Output is correct
76 Correct 7 ms 1016 KB Output is correct
77 Correct 7 ms 848 KB Output is correct
78 Correct 7 ms 1104 KB Output is correct
79 Correct 7 ms 860 KB Output is correct
80 Correct 7 ms 848 KB Output is correct
81 Correct 12 ms 1616 KB Output is correct
82 Correct 11 ms 1616 KB Output is correct
83 Correct 11 ms 1616 KB Output is correct
84 Correct 12 ms 1616 KB Output is correct
85 Correct 11 ms 1616 KB Output is correct
86 Correct 14 ms 2260 KB Output is correct
87 Correct 13 ms 2260 KB Output is correct
88 Correct 16 ms 2004 KB Output is correct
89 Correct 14 ms 2152 KB Output is correct
90 Correct 13 ms 2260 KB Output is correct
91 Correct 24 ms 5860 KB Output is correct
92 Correct 23 ms 6092 KB Output is correct
93 Correct 23 ms 6012 KB Output is correct
94 Correct 24 ms 6260 KB Output is correct
95 Correct 23 ms 5836 KB Output is correct
96 Correct 29 ms 10688 KB Output is correct
97 Correct 33 ms 12480 KB Output is correct
98 Correct 37 ms 12104 KB Output is correct
99 Correct 41 ms 12492 KB Output is correct
100 Correct 30 ms 10688 KB Output is correct
101 Correct 32 ms 11968 KB Output is correct
102 Correct 31 ms 12448 KB Output is correct
103 Correct 30 ms 11968 KB Output is correct
104 Correct 31 ms 12024 KB Output is correct
105 Correct 29 ms 10688 KB Output is correct
106 Correct 39 ms 14408 KB Output is correct
107 Correct 31 ms 14272 KB Output is correct
108 Correct 30 ms 12480 KB Output is correct
109 Correct 37 ms 14280 KB Output is correct
110 Correct 31 ms 12488 KB Output is correct
111 Correct 38 ms 13760 KB Output is correct
112 Correct 32 ms 12488 KB Output is correct
113 Correct 33 ms 13760 KB Output is correct
114 Correct 39 ms 13760 KB Output is correct
115 Correct 31 ms 12480 KB Output is correct
116 Incorrect 8 ms 1528 KB Output isn't correct
117 Halted 0 ms 0 KB -