답안 #999164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999164 2024-06-15T07:40:39 Z crafticat Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 28096 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;
        bool dir = true;
        for (auto [a, x] : v2) {
            if (last != x) {
                dir = !dir;
                if (dir) {
                    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 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 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 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 11 ms 6616 KB Output is correct
5 Correct 18 ms 10960 KB Output is correct
6 Correct 27 ms 17508 KB Output is correct
7 Correct 26 ms 17616 KB Output is correct
8 Correct 29 ms 17328 KB Output is correct
9 Correct 27 ms 17616 KB Output is correct
10 Correct 26 ms 17612 KB Output is correct
11 Correct 28 ms 17356 KB Output is correct
12 Correct 28 ms 17360 KB Output is correct
13 Correct 28 ms 17660 KB Output is correct
14 Correct 26 ms 17612 KB Output is correct
15 Correct 26 ms 16336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 11 ms 6616 KB Output is correct
5 Correct 18 ms 10960 KB Output is correct
6 Correct 27 ms 17508 KB Output is correct
7 Correct 26 ms 17616 KB Output is correct
8 Correct 29 ms 17328 KB Output is correct
9 Correct 27 ms 17616 KB Output is correct
10 Correct 26 ms 17612 KB Output is correct
11 Correct 28 ms 17356 KB Output is correct
12 Correct 28 ms 17360 KB Output is correct
13 Correct 28 ms 17660 KB Output is correct
14 Correct 26 ms 17612 KB Output is correct
15 Correct 26 ms 16336 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 3168 KB Output is correct
19 Correct 10 ms 6768 KB Output is correct
20 Correct 19 ms 11476 KB Output is correct
21 Correct 28 ms 16948 KB Output is correct
22 Correct 30 ms 17872 KB Output is correct
23 Correct 28 ms 17104 KB Output is correct
24 Correct 31 ms 16584 KB Output is correct
25 Correct 32 ms 18128 KB Output is correct
26 Correct 28 ms 16616 KB Output is correct
27 Correct 29 ms 17360 KB Output is correct
28 Correct 30 ms 17860 KB Output is correct
29 Correct 32 ms 17872 KB Output is correct
30 Correct 31 ms 18304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 11 ms 6616 KB Output is correct
5 Correct 18 ms 10960 KB Output is correct
6 Correct 27 ms 17508 KB Output is correct
7 Correct 26 ms 17616 KB Output is correct
8 Correct 29 ms 17328 KB Output is correct
9 Correct 27 ms 17616 KB Output is correct
10 Correct 26 ms 17612 KB Output is correct
11 Correct 28 ms 17356 KB Output is correct
12 Correct 28 ms 17360 KB Output is correct
13 Correct 28 ms 17660 KB Output is correct
14 Correct 26 ms 17612 KB Output is correct
15 Correct 26 ms 16336 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 3168 KB Output is correct
19 Correct 10 ms 6768 KB Output is correct
20 Correct 19 ms 11476 KB Output is correct
21 Correct 28 ms 16948 KB Output is correct
22 Correct 30 ms 17872 KB Output is correct
23 Correct 28 ms 17104 KB Output is correct
24 Correct 31 ms 16584 KB Output is correct
25 Correct 32 ms 18128 KB Output is correct
26 Correct 28 ms 16616 KB Output is correct
27 Correct 29 ms 17360 KB Output is correct
28 Correct 30 ms 17860 KB Output is correct
29 Correct 32 ms 17872 KB Output is correct
30 Correct 31 ms 18304 KB Output is correct
31 Correct 1 ms 2900 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 3284 KB Output is correct
35 Correct 2 ms 3288 KB Output is correct
36 Correct 2 ms 3288 KB Output is correct
37 Correct 8 ms 5336 KB Output is correct
38 Correct 7 ms 4828 KB Output is correct
39 Correct 13 ms 6868 KB Output is correct
40 Correct 25 ms 12764 KB Output is correct
41 Correct 36 ms 18128 KB Output is correct
42 Correct 41 ms 18628 KB Output is correct
43 Correct 34 ms 17360 KB Output is correct
44 Correct 35 ms 18020 KB Output is correct
45 Correct 36 ms 18380 KB Output is correct
46 Correct 36 ms 17612 KB Output is correct
47 Correct 36 ms 18640 KB Output is correct
48 Correct 35 ms 17616 KB Output is correct
49 Correct 35 ms 17616 KB Output is correct
50 Correct 36 ms 18384 KB Output is correct
51 Correct 34 ms 17240 KB Output is correct
52 Correct 35 ms 18640 KB Output is correct
53 Correct 35 ms 18372 KB Output is correct
54 Correct 34 ms 17104 KB Output is correct
55 Correct 37 ms 18276 KB Output is correct
56 Correct 36 ms 18376 KB Output is correct
57 Correct 35 ms 17104 KB Output is correct
58 Correct 36 ms 18380 KB Output is correct
59 Correct 35 ms 18636 KB Output is correct
60 Correct 36 ms 17104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 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 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 11 ms 6616 KB Output is correct
15 Correct 18 ms 10960 KB Output is correct
16 Correct 27 ms 17508 KB Output is correct
17 Correct 26 ms 17616 KB Output is correct
18 Correct 29 ms 17328 KB Output is correct
19 Correct 27 ms 17616 KB Output is correct
20 Correct 26 ms 17612 KB Output is correct
21 Correct 28 ms 17356 KB Output is correct
22 Correct 28 ms 17360 KB Output is correct
23 Correct 28 ms 17660 KB Output is correct
24 Correct 26 ms 17612 KB Output is correct
25 Correct 26 ms 16336 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 3168 KB Output is correct
29 Correct 10 ms 6768 KB Output is correct
30 Correct 19 ms 11476 KB Output is correct
31 Correct 28 ms 16948 KB Output is correct
32 Correct 30 ms 17872 KB Output is correct
33 Correct 28 ms 17104 KB Output is correct
34 Correct 31 ms 16584 KB Output is correct
35 Correct 32 ms 18128 KB Output is correct
36 Correct 28 ms 16616 KB Output is correct
37 Correct 29 ms 17360 KB Output is correct
38 Correct 30 ms 17860 KB Output is correct
39 Correct 32 ms 17872 KB Output is correct
40 Correct 31 ms 18304 KB Output is correct
41 Correct 1 ms 2900 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 3284 KB Output is correct
45 Correct 2 ms 3288 KB Output is correct
46 Correct 2 ms 3288 KB Output is correct
47 Correct 8 ms 5336 KB Output is correct
48 Correct 7 ms 4828 KB Output is correct
49 Correct 13 ms 6868 KB Output is correct
50 Correct 25 ms 12764 KB Output is correct
51 Correct 36 ms 18128 KB Output is correct
52 Correct 41 ms 18628 KB Output is correct
53 Correct 34 ms 17360 KB Output is correct
54 Correct 35 ms 18020 KB Output is correct
55 Correct 36 ms 18380 KB Output is correct
56 Correct 36 ms 17612 KB Output is correct
57 Correct 36 ms 18640 KB Output is correct
58 Correct 35 ms 17616 KB Output is correct
59 Correct 35 ms 17616 KB Output is correct
60 Correct 36 ms 18384 KB Output is correct
61 Correct 34 ms 17240 KB Output is correct
62 Correct 35 ms 18640 KB Output is correct
63 Correct 35 ms 18372 KB Output is correct
64 Correct 34 ms 17104 KB Output is correct
65 Correct 37 ms 18276 KB Output is correct
66 Correct 36 ms 18376 KB Output is correct
67 Correct 35 ms 17104 KB Output is correct
68 Correct 36 ms 18380 KB Output is correct
69 Correct 35 ms 18636 KB Output is correct
70 Correct 36 ms 17104 KB Output is correct
71 Correct 8 ms 4828 KB Output is correct
72 Correct 8 ms 4828 KB Output is correct
73 Correct 7 ms 4828 KB Output is correct
74 Correct 8 ms 4828 KB Output is correct
75 Correct 7 ms 4828 KB Output is correct
76 Correct 15 ms 6864 KB Output is correct
77 Correct 15 ms 6872 KB Output is correct
78 Correct 14 ms 7032 KB Output is correct
79 Correct 15 ms 6872 KB Output is correct
80 Correct 14 ms 7128 KB Output is correct
81 Correct 29 ms 10964 KB Output is correct
82 Correct 28 ms 12756 KB Output is correct
83 Correct 28 ms 12500 KB Output is correct
84 Correct 30 ms 12500 KB Output is correct
85 Correct 28 ms 12500 KB Output is correct
86 Correct 30 ms 11728 KB Output is correct
87 Correct 31 ms 13012 KB Output is correct
88 Correct 31 ms 12756 KB Output is correct
89 Correct 30 ms 11732 KB Output is correct
90 Correct 32 ms 13028 KB Output is correct
91 Correct 48 ms 20164 KB Output is correct
92 Correct 48 ms 20676 KB Output is correct
93 Correct 50 ms 20820 KB Output is correct
94 Correct 49 ms 19644 KB Output is correct
95 Correct 50 ms 20408 KB Output is correct
96 Correct 53 ms 26044 KB Output is correct
97 Correct 51 ms 25792 KB Output is correct
98 Correct 51 ms 25168 KB Output is correct
99 Correct 53 ms 27348 KB Output is correct
100 Correct 51 ms 25272 KB Output is correct
101 Correct 54 ms 25752 KB Output is correct
102 Correct 53 ms 25528 KB Output is correct
103 Correct 53 ms 26820 KB Output is correct
104 Correct 53 ms 27332 KB Output is correct
105 Correct 51 ms 26308 KB Output is correct
106 Correct 50 ms 27588 KB Output is correct
107 Correct 52 ms 27068 KB Output is correct
108 Correct 51 ms 27620 KB Output is correct
109 Correct 52 ms 27328 KB Output is correct
110 Correct 55 ms 27772 KB Output is correct
111 Correct 57 ms 27836 KB Output is correct
112 Correct 52 ms 28056 KB Output is correct
113 Correct 55 ms 27724 KB Output is correct
114 Correct 52 ms 27600 KB Output is correct
115 Correct 53 ms 28096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 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 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2772 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 11 ms 6616 KB Output is correct
15 Correct 18 ms 10960 KB Output is correct
16 Correct 27 ms 17508 KB Output is correct
17 Correct 26 ms 17616 KB Output is correct
18 Correct 29 ms 17328 KB Output is correct
19 Correct 27 ms 17616 KB Output is correct
20 Correct 26 ms 17612 KB Output is correct
21 Correct 28 ms 17356 KB Output is correct
22 Correct 28 ms 17360 KB Output is correct
23 Correct 28 ms 17660 KB Output is correct
24 Correct 26 ms 17612 KB Output is correct
25 Correct 26 ms 16336 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 3168 KB Output is correct
29 Correct 10 ms 6768 KB Output is correct
30 Correct 19 ms 11476 KB Output is correct
31 Correct 28 ms 16948 KB Output is correct
32 Correct 30 ms 17872 KB Output is correct
33 Correct 28 ms 17104 KB Output is correct
34 Correct 31 ms 16584 KB Output is correct
35 Correct 32 ms 18128 KB Output is correct
36 Correct 28 ms 16616 KB Output is correct
37 Correct 29 ms 17360 KB Output is correct
38 Correct 30 ms 17860 KB Output is correct
39 Correct 32 ms 17872 KB Output is correct
40 Correct 31 ms 18304 KB Output is correct
41 Correct 1 ms 2900 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 2 ms 3284 KB Output is correct
45 Correct 2 ms 3288 KB Output is correct
46 Correct 2 ms 3288 KB Output is correct
47 Correct 8 ms 5336 KB Output is correct
48 Correct 7 ms 4828 KB Output is correct
49 Correct 13 ms 6868 KB Output is correct
50 Correct 25 ms 12764 KB Output is correct
51 Correct 36 ms 18128 KB Output is correct
52 Correct 41 ms 18628 KB Output is correct
53 Correct 34 ms 17360 KB Output is correct
54 Correct 35 ms 18020 KB Output is correct
55 Correct 36 ms 18380 KB Output is correct
56 Correct 36 ms 17612 KB Output is correct
57 Correct 36 ms 18640 KB Output is correct
58 Correct 35 ms 17616 KB Output is correct
59 Correct 35 ms 17616 KB Output is correct
60 Correct 36 ms 18384 KB Output is correct
61 Correct 34 ms 17240 KB Output is correct
62 Correct 35 ms 18640 KB Output is correct
63 Correct 35 ms 18372 KB Output is correct
64 Correct 34 ms 17104 KB Output is correct
65 Correct 37 ms 18276 KB Output is correct
66 Correct 36 ms 18376 KB Output is correct
67 Correct 35 ms 17104 KB Output is correct
68 Correct 36 ms 18380 KB Output is correct
69 Correct 35 ms 18636 KB Output is correct
70 Correct 36 ms 17104 KB Output is correct
71 Correct 8 ms 4828 KB Output is correct
72 Correct 8 ms 4828 KB Output is correct
73 Correct 7 ms 4828 KB Output is correct
74 Correct 8 ms 4828 KB Output is correct
75 Correct 7 ms 4828 KB Output is correct
76 Correct 15 ms 6864 KB Output is correct
77 Correct 15 ms 6872 KB Output is correct
78 Correct 14 ms 7032 KB Output is correct
79 Correct 15 ms 6872 KB Output is correct
80 Correct 14 ms 7128 KB Output is correct
81 Correct 29 ms 10964 KB Output is correct
82 Correct 28 ms 12756 KB Output is correct
83 Correct 28 ms 12500 KB Output is correct
84 Correct 30 ms 12500 KB Output is correct
85 Correct 28 ms 12500 KB Output is correct
86 Correct 30 ms 11728 KB Output is correct
87 Correct 31 ms 13012 KB Output is correct
88 Correct 31 ms 12756 KB Output is correct
89 Correct 30 ms 11732 KB Output is correct
90 Correct 32 ms 13028 KB Output is correct
91 Correct 48 ms 20164 KB Output is correct
92 Correct 48 ms 20676 KB Output is correct
93 Correct 50 ms 20820 KB Output is correct
94 Correct 49 ms 19644 KB Output is correct
95 Correct 50 ms 20408 KB Output is correct
96 Correct 53 ms 26044 KB Output is correct
97 Correct 51 ms 25792 KB Output is correct
98 Correct 51 ms 25168 KB Output is correct
99 Correct 53 ms 27348 KB Output is correct
100 Correct 51 ms 25272 KB Output is correct
101 Correct 54 ms 25752 KB Output is correct
102 Correct 53 ms 25528 KB Output is correct
103 Correct 53 ms 26820 KB Output is correct
104 Correct 53 ms 27332 KB Output is correct
105 Correct 51 ms 26308 KB Output is correct
106 Correct 50 ms 27588 KB Output is correct
107 Correct 52 ms 27068 KB Output is correct
108 Correct 51 ms 27620 KB Output is correct
109 Correct 52 ms 27328 KB Output is correct
110 Correct 55 ms 27772 KB Output is correct
111 Correct 57 ms 27836 KB Output is correct
112 Correct 52 ms 28056 KB Output is correct
113 Correct 55 ms 27724 KB Output is correct
114 Correct 52 ms 27600 KB Output is correct
115 Correct 53 ms 28096 KB Output is correct
116 Execution timed out 7074 ms 4156 KB Time limit exceeded
117 Halted 0 ms 0 KB -