답안 #999161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999161 2024-06-15T07:34:59 Z crafticat Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 26304 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

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

    ll n, q; cin >> n >> q;
    vector<ll> arr(n);
    for (ll i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    for (ll i = 0; i < q; ++i) {
        ll l, r; cin >> l >> r;
        l--;
        vector<ll> v;
        vector<ll> app(300002);
        v.reserve(r - l);
        ll s = r - l;
        for (ll j = l; j < r; ++j) {
            v.push_back(arr[j]);
        }
        for (auto x : v) {
            app[x]++;
        }
        vector<pii> v2;
        for (auto x : v) {
            v2.emplace_back(app[x],x);
        }
        std::sort(v2.begin(), v2.end());
        vector<pii> orderA, orderB;
        ll last = -1;
        ll leftS = 0, rightS = 0;
        for (auto [a, x] : v2) {
            if (last != x) {
                if (leftS <= rightS) {
                    orderA.emplace_back(x, a);
                    leftS += a;
                }
                else {
                    orderB.emplace_back(x,a);
                    rightS += a;
                }
            }
            last = x;
        }
        vector<pii> order;
        for (auto x : orderA) {
            order.push_back(x);
        }
        std::reverse(orderB.begin(), orderB.end());
        for (auto x : orderB) {
            order.push_back(x);
        }

        ll a = 0;
        ll ans = 0;
        for (auto [x, amount] : order) {
            ll b = a + amount;
            ll includeSub = a * (s - b);
            ll includePar = a * amount + (s - b) * amount;
            ll self = amount * (amount + 1) / 2;
            ans += self + includePar + includeSub;
            a += amount;
        }

        cout << ans << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3344 KB Output is correct
4 Correct 9 ms 6424 KB Output is correct
5 Correct 17 ms 10452 KB Output is correct
6 Correct 27 ms 17360 KB Output is correct
7 Correct 26 ms 17612 KB Output is correct
8 Correct 27 ms 15908 KB Output is correct
9 Correct 27 ms 16080 KB Output is correct
10 Correct 28 ms 17616 KB Output is correct
11 Correct 30 ms 17356 KB Output is correct
12 Correct 27 ms 17104 KB Output is correct
13 Correct 27 ms 17360 KB Output is correct
14 Correct 27 ms 17360 KB Output is correct
15 Correct 26 ms 16592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3344 KB Output is correct
4 Correct 9 ms 6424 KB Output is correct
5 Correct 17 ms 10452 KB Output is correct
6 Correct 27 ms 17360 KB Output is correct
7 Correct 26 ms 17612 KB Output is correct
8 Correct 27 ms 15908 KB Output is correct
9 Correct 27 ms 16080 KB Output is correct
10 Correct 28 ms 17616 KB Output is correct
11 Correct 30 ms 17356 KB Output is correct
12 Correct 27 ms 17104 KB Output is correct
13 Correct 27 ms 17360 KB Output is correct
14 Correct 27 ms 17360 KB Output is correct
15 Correct 26 ms 16592 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 3164 KB Output is correct
19 Correct 9 ms 6356 KB Output is correct
20 Correct 21 ms 10964 KB Output is correct
21 Correct 31 ms 17104 KB Output is correct
22 Correct 30 ms 16848 KB Output is correct
23 Correct 29 ms 17268 KB Output is correct
24 Correct 29 ms 15824 KB Output is correct
25 Correct 29 ms 17360 KB Output is correct
26 Correct 29 ms 16332 KB Output is correct
27 Correct 33 ms 17104 KB Output is correct
28 Correct 30 ms 17360 KB Output is correct
29 Correct 28 ms 16104 KB Output is correct
30 Correct 30 ms 17100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3344 KB Output is correct
4 Correct 9 ms 6424 KB Output is correct
5 Correct 17 ms 10452 KB Output is correct
6 Correct 27 ms 17360 KB Output is correct
7 Correct 26 ms 17612 KB Output is correct
8 Correct 27 ms 15908 KB Output is correct
9 Correct 27 ms 16080 KB Output is correct
10 Correct 28 ms 17616 KB Output is correct
11 Correct 30 ms 17356 KB Output is correct
12 Correct 27 ms 17104 KB Output is correct
13 Correct 27 ms 17360 KB Output is correct
14 Correct 27 ms 17360 KB Output is correct
15 Correct 26 ms 16592 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 3164 KB Output is correct
19 Correct 9 ms 6356 KB Output is correct
20 Correct 21 ms 10964 KB Output is correct
21 Correct 31 ms 17104 KB Output is correct
22 Correct 30 ms 16848 KB Output is correct
23 Correct 29 ms 17268 KB Output is correct
24 Correct 29 ms 15824 KB Output is correct
25 Correct 29 ms 17360 KB Output is correct
26 Correct 29 ms 16332 KB Output is correct
27 Correct 33 ms 17104 KB Output is correct
28 Correct 30 ms 17360 KB Output is correct
29 Correct 28 ms 16104 KB Output is correct
30 Correct 30 ms 17100 KB Output is correct
31 Correct 2 ms 2648 KB Output is correct
32 Correct 2 ms 2648 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 2 ms 3164 KB Output is correct
35 Correct 2 ms 3164 KB Output is correct
36 Correct 2 ms 3164 KB Output is correct
37 Correct 7 ms 4568 KB Output is correct
38 Correct 7 ms 4572 KB Output is correct
39 Correct 13 ms 6356 KB Output is correct
40 Correct 24 ms 11216 KB Output is correct
41 Correct 35 ms 17104 KB Output is correct
42 Correct 36 ms 17100 KB Output is correct
43 Correct 33 ms 16080 KB Output is correct
44 Correct 35 ms 17360 KB Output is correct
45 Correct 35 ms 15820 KB Output is correct
46 Correct 37 ms 17104 KB Output is correct
47 Correct 34 ms 16248 KB Output is correct
48 Correct 35 ms 17616 KB Output is correct
49 Correct 34 ms 15820 KB Output is correct
50 Correct 34 ms 17072 KB Output is correct
51 Correct 35 ms 17268 KB Output is correct
52 Correct 37 ms 17360 KB Output is correct
53 Correct 36 ms 17104 KB Output is correct
54 Correct 34 ms 17104 KB Output is correct
55 Correct 34 ms 15788 KB Output is correct
56 Correct 35 ms 17012 KB Output is correct
57 Correct 36 ms 17104 KB Output is correct
58 Correct 36 ms 17104 KB Output is correct
59 Correct 34 ms 17616 KB Output is correct
60 Correct 35 ms 17616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 3344 KB Output is correct
14 Correct 9 ms 6424 KB Output is correct
15 Correct 17 ms 10452 KB Output is correct
16 Correct 27 ms 17360 KB Output is correct
17 Correct 26 ms 17612 KB Output is correct
18 Correct 27 ms 15908 KB Output is correct
19 Correct 27 ms 16080 KB Output is correct
20 Correct 28 ms 17616 KB Output is correct
21 Correct 30 ms 17356 KB Output is correct
22 Correct 27 ms 17104 KB Output is correct
23 Correct 27 ms 17360 KB Output is correct
24 Correct 27 ms 17360 KB Output is correct
25 Correct 26 ms 16592 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 9 ms 6356 KB Output is correct
30 Correct 21 ms 10964 KB Output is correct
31 Correct 31 ms 17104 KB Output is correct
32 Correct 30 ms 16848 KB Output is correct
33 Correct 29 ms 17268 KB Output is correct
34 Correct 29 ms 15824 KB Output is correct
35 Correct 29 ms 17360 KB Output is correct
36 Correct 29 ms 16332 KB Output is correct
37 Correct 33 ms 17104 KB Output is correct
38 Correct 30 ms 17360 KB Output is correct
39 Correct 28 ms 16104 KB Output is correct
40 Correct 30 ms 17100 KB Output is correct
41 Correct 2 ms 2648 KB Output is correct
42 Correct 2 ms 2648 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 2 ms 3164 KB Output is correct
45 Correct 2 ms 3164 KB Output is correct
46 Correct 2 ms 3164 KB Output is correct
47 Correct 7 ms 4568 KB Output is correct
48 Correct 7 ms 4572 KB Output is correct
49 Correct 13 ms 6356 KB Output is correct
50 Correct 24 ms 11216 KB Output is correct
51 Correct 35 ms 17104 KB Output is correct
52 Correct 36 ms 17100 KB Output is correct
53 Correct 33 ms 16080 KB Output is correct
54 Correct 35 ms 17360 KB Output is correct
55 Correct 35 ms 15820 KB Output is correct
56 Correct 37 ms 17104 KB Output is correct
57 Correct 34 ms 16248 KB Output is correct
58 Correct 35 ms 17616 KB Output is correct
59 Correct 34 ms 15820 KB Output is correct
60 Correct 34 ms 17072 KB Output is correct
61 Correct 35 ms 17268 KB Output is correct
62 Correct 37 ms 17360 KB Output is correct
63 Correct 36 ms 17104 KB Output is correct
64 Correct 34 ms 17104 KB Output is correct
65 Correct 34 ms 15788 KB Output is correct
66 Correct 35 ms 17012 KB Output is correct
67 Correct 36 ms 17104 KB Output is correct
68 Correct 36 ms 17104 KB Output is correct
69 Correct 34 ms 17616 KB Output is correct
70 Correct 35 ms 17616 KB Output is correct
71 Correct 7 ms 4824 KB Output is correct
72 Correct 8 ms 4572 KB Output is correct
73 Correct 8 ms 4584 KB Output is correct
74 Correct 8 ms 4572 KB Output is correct
75 Correct 7 ms 4572 KB Output is correct
76 Correct 14 ms 6360 KB Output is correct
77 Correct 14 ms 6360 KB Output is correct
78 Correct 15 ms 6356 KB Output is correct
79 Correct 14 ms 6500 KB Output is correct
80 Correct 14 ms 6360 KB Output is correct
81 Correct 28 ms 11968 KB Output is correct
82 Correct 29 ms 10704 KB Output is correct
83 Correct 29 ms 10452 KB Output is correct
84 Correct 28 ms 11988 KB Output is correct
85 Correct 29 ms 11112 KB Output is correct
86 Correct 30 ms 11732 KB Output is correct
87 Correct 30 ms 11308 KB Output is correct
88 Correct 30 ms 10452 KB Output is correct
89 Correct 30 ms 11984 KB Output is correct
90 Correct 32 ms 11988 KB Output is correct
91 Correct 51 ms 18856 KB Output is correct
92 Correct 48 ms 19232 KB Output is correct
93 Correct 49 ms 19136 KB Output is correct
94 Correct 49 ms 19388 KB Output is correct
95 Correct 49 ms 18628 KB Output is correct
96 Correct 53 ms 23488 KB Output is correct
97 Correct 49 ms 24680 KB Output is correct
98 Correct 51 ms 25280 KB Output is correct
99 Correct 52 ms 24764 KB Output is correct
100 Correct 49 ms 25016 KB Output is correct
101 Correct 53 ms 24256 KB Output is correct
102 Correct 54 ms 25788 KB Output is correct
103 Correct 51 ms 23500 KB Output is correct
104 Correct 51 ms 24252 KB Output is correct
105 Correct 50 ms 25276 KB Output is correct
106 Correct 51 ms 25528 KB Output is correct
107 Correct 52 ms 24696 KB Output is correct
108 Correct 51 ms 24512 KB Output is correct
109 Correct 49 ms 26020 KB Output is correct
110 Correct 50 ms 24636 KB Output is correct
111 Correct 52 ms 25056 KB Output is correct
112 Correct 51 ms 25792 KB Output is correct
113 Correct 52 ms 25668 KB Output is correct
114 Correct 51 ms 26304 KB Output is correct
115 Correct 52 ms 24792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 3344 KB Output is correct
14 Correct 9 ms 6424 KB Output is correct
15 Correct 17 ms 10452 KB Output is correct
16 Correct 27 ms 17360 KB Output is correct
17 Correct 26 ms 17612 KB Output is correct
18 Correct 27 ms 15908 KB Output is correct
19 Correct 27 ms 16080 KB Output is correct
20 Correct 28 ms 17616 KB Output is correct
21 Correct 30 ms 17356 KB Output is correct
22 Correct 27 ms 17104 KB Output is correct
23 Correct 27 ms 17360 KB Output is correct
24 Correct 27 ms 17360 KB Output is correct
25 Correct 26 ms 16592 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 9 ms 6356 KB Output is correct
30 Correct 21 ms 10964 KB Output is correct
31 Correct 31 ms 17104 KB Output is correct
32 Correct 30 ms 16848 KB Output is correct
33 Correct 29 ms 17268 KB Output is correct
34 Correct 29 ms 15824 KB Output is correct
35 Correct 29 ms 17360 KB Output is correct
36 Correct 29 ms 16332 KB Output is correct
37 Correct 33 ms 17104 KB Output is correct
38 Correct 30 ms 17360 KB Output is correct
39 Correct 28 ms 16104 KB Output is correct
40 Correct 30 ms 17100 KB Output is correct
41 Correct 2 ms 2648 KB Output is correct
42 Correct 2 ms 2648 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 2 ms 3164 KB Output is correct
45 Correct 2 ms 3164 KB Output is correct
46 Correct 2 ms 3164 KB Output is correct
47 Correct 7 ms 4568 KB Output is correct
48 Correct 7 ms 4572 KB Output is correct
49 Correct 13 ms 6356 KB Output is correct
50 Correct 24 ms 11216 KB Output is correct
51 Correct 35 ms 17104 KB Output is correct
52 Correct 36 ms 17100 KB Output is correct
53 Correct 33 ms 16080 KB Output is correct
54 Correct 35 ms 17360 KB Output is correct
55 Correct 35 ms 15820 KB Output is correct
56 Correct 37 ms 17104 KB Output is correct
57 Correct 34 ms 16248 KB Output is correct
58 Correct 35 ms 17616 KB Output is correct
59 Correct 34 ms 15820 KB Output is correct
60 Correct 34 ms 17072 KB Output is correct
61 Correct 35 ms 17268 KB Output is correct
62 Correct 37 ms 17360 KB Output is correct
63 Correct 36 ms 17104 KB Output is correct
64 Correct 34 ms 17104 KB Output is correct
65 Correct 34 ms 15788 KB Output is correct
66 Correct 35 ms 17012 KB Output is correct
67 Correct 36 ms 17104 KB Output is correct
68 Correct 36 ms 17104 KB Output is correct
69 Correct 34 ms 17616 KB Output is correct
70 Correct 35 ms 17616 KB Output is correct
71 Correct 7 ms 4824 KB Output is correct
72 Correct 8 ms 4572 KB Output is correct
73 Correct 8 ms 4584 KB Output is correct
74 Correct 8 ms 4572 KB Output is correct
75 Correct 7 ms 4572 KB Output is correct
76 Correct 14 ms 6360 KB Output is correct
77 Correct 14 ms 6360 KB Output is correct
78 Correct 15 ms 6356 KB Output is correct
79 Correct 14 ms 6500 KB Output is correct
80 Correct 14 ms 6360 KB Output is correct
81 Correct 28 ms 11968 KB Output is correct
82 Correct 29 ms 10704 KB Output is correct
83 Correct 29 ms 10452 KB Output is correct
84 Correct 28 ms 11988 KB Output is correct
85 Correct 29 ms 11112 KB Output is correct
86 Correct 30 ms 11732 KB Output is correct
87 Correct 30 ms 11308 KB Output is correct
88 Correct 30 ms 10452 KB Output is correct
89 Correct 30 ms 11984 KB Output is correct
90 Correct 32 ms 11988 KB Output is correct
91 Correct 51 ms 18856 KB Output is correct
92 Correct 48 ms 19232 KB Output is correct
93 Correct 49 ms 19136 KB Output is correct
94 Correct 49 ms 19388 KB Output is correct
95 Correct 49 ms 18628 KB Output is correct
96 Correct 53 ms 23488 KB Output is correct
97 Correct 49 ms 24680 KB Output is correct
98 Correct 51 ms 25280 KB Output is correct
99 Correct 52 ms 24764 KB Output is correct
100 Correct 49 ms 25016 KB Output is correct
101 Correct 53 ms 24256 KB Output is correct
102 Correct 54 ms 25788 KB Output is correct
103 Correct 51 ms 23500 KB Output is correct
104 Correct 51 ms 24252 KB Output is correct
105 Correct 50 ms 25276 KB Output is correct
106 Correct 51 ms 25528 KB Output is correct
107 Correct 52 ms 24696 KB Output is correct
108 Correct 51 ms 24512 KB Output is correct
109 Correct 49 ms 26020 KB Output is correct
110 Correct 50 ms 24636 KB Output is correct
111 Correct 52 ms 25056 KB Output is correct
112 Correct 51 ms 25792 KB Output is correct
113 Correct 52 ms 25668 KB Output is correct
114 Correct 51 ms 26304 KB Output is correct
115 Correct 52 ms 24792 KB Output is correct
116 Execution timed out 7075 ms 3512 KB Time limit exceeded
117 Halted 0 ms 0 KB -