답안 #999137

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;


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

    ll n, q;
    cin >> n >> q;

    vector<ll> arr(n);
    for (auto &ref: arr) cin >> ref;


    while (q--) {
        ll left, right;
        cin >> left >> right;
        left--;

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

        vector<ll> lens;
        {
            vector<ll> raw_lens;
            ll last = -1;
            for (ll i = 0; i < n; i++) {
                if (last == -1) {
                    last = i;
                    continue;
                }

                if (arr[i] == arr[last]) {}
                else {
                    raw_lens.push_back(i - last);
                    last = i;
                }
            }
            raw_lens.push_back(n - last);
            std::sort(raw_lens.begin(), raw_lens.end());

            vector<ll> first, second;
            ll i = 0;
            while (true) {
                if (i < raw_lens.size()) {
                    first.push_back(raw_lens[i]);
                    i++;
                } else break;

                if (i < raw_lens.size()) {
                    second.push_back(raw_lens[i]);
                    i++;
                } else break;
            }

            for (ll l: first)
                lens.push_back(l);
            for (auto it = second.rbegin(); it != second.rend(); it++)
                lens.push_back(*it);
        }

        struct ptr {
            ll in;
            ll cnt;
        };
        auto advance = [&](ptr &ptr) {
            if (ptr.cnt + 1 == lens[ptr.in]) {
                ptr.cnt = 0;
                ptr.in++;
            } else ptr.cnt++;
        };

        ll total = 0;
        {
            ll bias = 0;
            vector<ll> uniques;
            {
                ptr first{0, 0};
                ptr second{0, 0};
                for (ll sublen = 1; sublen <= n; sublen++) {

                    uniques.push_back(second.in - first.in + 1);
                    advance(second);
                }
            }

            ll sum = accumulate(uniques.begin(), uniques.end(), 0ll);
            total = sum;
            for (ll i = 1; i < uniques.size(); i++) {
                sum -= (uniques[i - 1] - bias);

                if ((uniques[i] - bias) == 2) {
                    bias++;
                    sum -= uniques.size() - i;
                }

                total += sum;
            }
        }

        cout << total << "\n";
    }

}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:52:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 if (i < raw_lens.size()) {
      |                     ~~^~~~~~~~~~~~~~~~~
diversity.cpp:57:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 if (i < raw_lens.size()) {
      |                     ~~^~~~~~~~~~~~~~~~~
diversity.cpp:96:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             for (ll i = 1; i < uniques.size(); i++) {
      |                            ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 13 ms 4608 KB Output is correct
6 Correct 22 ms 8984 KB Output is correct
7 Correct 20 ms 8468 KB Output is correct
8 Correct 26 ms 8676 KB Output is correct
9 Correct 24 ms 9164 KB Output is correct
10 Correct 24 ms 9416 KB Output is correct
11 Correct 21 ms 8912 KB Output is correct
12 Correct 22 ms 9492 KB Output is correct
13 Correct 22 ms 9428 KB Output is correct
14 Correct 21 ms 7776 KB Output is correct
15 Correct 24 ms 7664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 13 ms 4608 KB Output is correct
6 Correct 22 ms 8984 KB Output is correct
7 Correct 20 ms 8468 KB Output is correct
8 Correct 26 ms 8676 KB Output is correct
9 Correct 24 ms 9164 KB Output is correct
10 Correct 24 ms 9416 KB Output is correct
11 Correct 21 ms 8912 KB Output is correct
12 Correct 22 ms 9492 KB Output is correct
13 Correct 22 ms 9428 KB Output is correct
14 Correct 21 ms 7776 KB Output is correct
15 Correct 24 ms 7664 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 9 ms 2672 KB Output is correct
20 Correct 23 ms 4568 KB Output is correct
21 Correct 24 ms 8592 KB Output is correct
22 Correct 24 ms 8036 KB Output is correct
23 Correct 25 ms 8912 KB Output is correct
24 Correct 23 ms 9352 KB Output is correct
25 Correct 22 ms 7892 KB Output is correct
26 Correct 25 ms 9628 KB Output is correct
27 Correct 26 ms 8660 KB Output is correct
28 Correct 23 ms 8916 KB Output is correct
29 Correct 24 ms 8404 KB Output is correct
30 Correct 24 ms 9364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 8 ms 2516 KB Output is correct
5 Correct 13 ms 4608 KB Output is correct
6 Correct 22 ms 8984 KB Output is correct
7 Correct 20 ms 8468 KB Output is correct
8 Correct 26 ms 8676 KB Output is correct
9 Correct 24 ms 9164 KB Output is correct
10 Correct 24 ms 9416 KB Output is correct
11 Correct 21 ms 8912 KB Output is correct
12 Correct 22 ms 9492 KB Output is correct
13 Correct 22 ms 9428 KB Output is correct
14 Correct 21 ms 7776 KB Output is correct
15 Correct 24 ms 7664 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 9 ms 2672 KB Output is correct
20 Correct 23 ms 4568 KB Output is correct
21 Correct 24 ms 8592 KB Output is correct
22 Correct 24 ms 8036 KB Output is correct
23 Correct 25 ms 8912 KB Output is correct
24 Correct 23 ms 9352 KB Output is correct
25 Correct 22 ms 7892 KB Output is correct
26 Correct 25 ms 9628 KB Output is correct
27 Correct 26 ms 8660 KB Output is correct
28 Correct 23 ms 8916 KB Output is correct
29 Correct 24 ms 8404 KB Output is correct
30 Correct 24 ms 9364 KB Output is correct
31 Correct 1 ms 344 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 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 2 ms 600 KB Output is correct
37 Correct 6 ms 1620 KB Output is correct
38 Correct 5 ms 1516 KB Output is correct
39 Correct 10 ms 2792 KB Output is correct
40 Correct 19 ms 4960 KB Output is correct
41 Correct 32 ms 8668 KB Output is correct
42 Correct 30 ms 9172 KB Output is correct
43 Correct 40 ms 8300 KB Output is correct
44 Correct 30 ms 9440 KB Output is correct
45 Correct 31 ms 8568 KB Output is correct
46 Correct 28 ms 10228 KB Output is correct
47 Correct 41 ms 8920 KB Output is correct
48 Correct 30 ms 9688 KB Output is correct
49 Correct 28 ms 8168 KB Output is correct
50 Correct 29 ms 9184 KB Output is correct
51 Correct 28 ms 9952 KB Output is correct
52 Correct 31 ms 9580 KB Output is correct
53 Correct 29 ms 9460 KB Output is correct
54 Correct 29 ms 8408 KB Output is correct
55 Correct 29 ms 8432 KB Output is correct
56 Correct 29 ms 8660 KB Output is correct
57 Correct 31 ms 9688 KB Output is correct
58 Correct 28 ms 8948 KB Output is correct
59 Correct 29 ms 8904 KB Output is correct
60 Correct 28 ms 8664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 8 ms 2516 KB Output is correct
15 Correct 13 ms 4608 KB Output is correct
16 Correct 22 ms 8984 KB Output is correct
17 Correct 20 ms 8468 KB Output is correct
18 Correct 26 ms 8676 KB Output is correct
19 Correct 24 ms 9164 KB Output is correct
20 Correct 24 ms 9416 KB Output is correct
21 Correct 21 ms 8912 KB Output is correct
22 Correct 22 ms 9492 KB Output is correct
23 Correct 22 ms 9428 KB Output is correct
24 Correct 21 ms 7776 KB Output is correct
25 Correct 24 ms 7664 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 9 ms 2672 KB Output is correct
30 Correct 23 ms 4568 KB Output is correct
31 Correct 24 ms 8592 KB Output is correct
32 Correct 24 ms 8036 KB Output is correct
33 Correct 25 ms 8912 KB Output is correct
34 Correct 23 ms 9352 KB Output is correct
35 Correct 22 ms 7892 KB Output is correct
36 Correct 25 ms 9628 KB Output is correct
37 Correct 26 ms 8660 KB Output is correct
38 Correct 23 ms 8916 KB Output is correct
39 Correct 24 ms 8404 KB Output is correct
40 Correct 24 ms 9364 KB Output is correct
41 Correct 1 ms 344 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 604 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 2 ms 600 KB Output is correct
47 Correct 6 ms 1620 KB Output is correct
48 Correct 5 ms 1516 KB Output is correct
49 Correct 10 ms 2792 KB Output is correct
50 Correct 19 ms 4960 KB Output is correct
51 Correct 32 ms 8668 KB Output is correct
52 Correct 30 ms 9172 KB Output is correct
53 Correct 40 ms 8300 KB Output is correct
54 Correct 30 ms 9440 KB Output is correct
55 Correct 31 ms 8568 KB Output is correct
56 Correct 28 ms 10228 KB Output is correct
57 Correct 41 ms 8920 KB Output is correct
58 Correct 30 ms 9688 KB Output is correct
59 Correct 28 ms 8168 KB Output is correct
60 Correct 29 ms 9184 KB Output is correct
61 Correct 28 ms 9952 KB Output is correct
62 Correct 31 ms 9580 KB Output is correct
63 Correct 29 ms 9460 KB Output is correct
64 Correct 29 ms 8408 KB Output is correct
65 Correct 29 ms 8432 KB Output is correct
66 Correct 29 ms 8660 KB Output is correct
67 Correct 31 ms 9688 KB Output is correct
68 Correct 28 ms 8948 KB Output is correct
69 Correct 29 ms 8904 KB Output is correct
70 Correct 28 ms 8664 KB Output is correct
71 Correct 6 ms 1720 KB Output is correct
72 Correct 6 ms 1752 KB Output is correct
73 Correct 5 ms 1752 KB Output is correct
74 Correct 5 ms 1548 KB Output is correct
75 Correct 6 ms 1752 KB Output is correct
76 Correct 11 ms 3000 KB Output is correct
77 Correct 15 ms 2904 KB Output is correct
78 Correct 11 ms 2904 KB Output is correct
79 Correct 12 ms 2888 KB Output is correct
80 Correct 13 ms 2900 KB Output is correct
81 Correct 31 ms 5108 KB Output is correct
82 Correct 22 ms 5108 KB Output is correct
83 Correct 23 ms 5184 KB Output is correct
84 Correct 22 ms 5108 KB Output is correct
85 Correct 26 ms 5200 KB Output is correct
86 Correct 27 ms 5284 KB Output is correct
87 Correct 24 ms 5352 KB Output is correct
88 Correct 24 ms 5276 KB Output is correct
89 Correct 34 ms 5344 KB Output is correct
90 Correct 26 ms 5280 KB Output is correct
91 Correct 42 ms 10980 KB Output is correct
92 Correct 42 ms 10720 KB Output is correct
93 Correct 45 ms 9944 KB Output is correct
94 Correct 42 ms 10608 KB Output is correct
95 Correct 47 ms 10056 KB Output is correct
96 Correct 51 ms 13500 KB Output is correct
97 Correct 53 ms 13756 KB Output is correct
98 Correct 55 ms 14004 KB Output is correct
99 Correct 62 ms 12724 KB Output is correct
100 Correct 48 ms 13028 KB Output is correct
101 Correct 55 ms 13248 KB Output is correct
102 Correct 50 ms 14272 KB Output is correct
103 Correct 52 ms 12744 KB Output is correct
104 Correct 51 ms 12728 KB Output is correct
105 Correct 51 ms 13492 KB Output is correct
106 Correct 66 ms 13996 KB Output is correct
107 Correct 48 ms 14528 KB Output is correct
108 Correct 51 ms 14248 KB Output is correct
109 Correct 50 ms 13248 KB Output is correct
110 Correct 49 ms 13248 KB Output is correct
111 Correct 49 ms 12772 KB Output is correct
112 Correct 51 ms 13740 KB Output is correct
113 Correct 47 ms 13224 KB Output is correct
114 Correct 52 ms 12788 KB Output is correct
115 Correct 49 ms 12972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 8 ms 2516 KB Output is correct
15 Correct 13 ms 4608 KB Output is correct
16 Correct 22 ms 8984 KB Output is correct
17 Correct 20 ms 8468 KB Output is correct
18 Correct 26 ms 8676 KB Output is correct
19 Correct 24 ms 9164 KB Output is correct
20 Correct 24 ms 9416 KB Output is correct
21 Correct 21 ms 8912 KB Output is correct
22 Correct 22 ms 9492 KB Output is correct
23 Correct 22 ms 9428 KB Output is correct
24 Correct 21 ms 7776 KB Output is correct
25 Correct 24 ms 7664 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 9 ms 2672 KB Output is correct
30 Correct 23 ms 4568 KB Output is correct
31 Correct 24 ms 8592 KB Output is correct
32 Correct 24 ms 8036 KB Output is correct
33 Correct 25 ms 8912 KB Output is correct
34 Correct 23 ms 9352 KB Output is correct
35 Correct 22 ms 7892 KB Output is correct
36 Correct 25 ms 9628 KB Output is correct
37 Correct 26 ms 8660 KB Output is correct
38 Correct 23 ms 8916 KB Output is correct
39 Correct 24 ms 8404 KB Output is correct
40 Correct 24 ms 9364 KB Output is correct
41 Correct 1 ms 344 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 604 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 2 ms 600 KB Output is correct
47 Correct 6 ms 1620 KB Output is correct
48 Correct 5 ms 1516 KB Output is correct
49 Correct 10 ms 2792 KB Output is correct
50 Correct 19 ms 4960 KB Output is correct
51 Correct 32 ms 8668 KB Output is correct
52 Correct 30 ms 9172 KB Output is correct
53 Correct 40 ms 8300 KB Output is correct
54 Correct 30 ms 9440 KB Output is correct
55 Correct 31 ms 8568 KB Output is correct
56 Correct 28 ms 10228 KB Output is correct
57 Correct 41 ms 8920 KB Output is correct
58 Correct 30 ms 9688 KB Output is correct
59 Correct 28 ms 8168 KB Output is correct
60 Correct 29 ms 9184 KB Output is correct
61 Correct 28 ms 9952 KB Output is correct
62 Correct 31 ms 9580 KB Output is correct
63 Correct 29 ms 9460 KB Output is correct
64 Correct 29 ms 8408 KB Output is correct
65 Correct 29 ms 8432 KB Output is correct
66 Correct 29 ms 8660 KB Output is correct
67 Correct 31 ms 9688 KB Output is correct
68 Correct 28 ms 8948 KB Output is correct
69 Correct 29 ms 8904 KB Output is correct
70 Correct 28 ms 8664 KB Output is correct
71 Correct 6 ms 1720 KB Output is correct
72 Correct 6 ms 1752 KB Output is correct
73 Correct 5 ms 1752 KB Output is correct
74 Correct 5 ms 1548 KB Output is correct
75 Correct 6 ms 1752 KB Output is correct
76 Correct 11 ms 3000 KB Output is correct
77 Correct 15 ms 2904 KB Output is correct
78 Correct 11 ms 2904 KB Output is correct
79 Correct 12 ms 2888 KB Output is correct
80 Correct 13 ms 2900 KB Output is correct
81 Correct 31 ms 5108 KB Output is correct
82 Correct 22 ms 5108 KB Output is correct
83 Correct 23 ms 5184 KB Output is correct
84 Correct 22 ms 5108 KB Output is correct
85 Correct 26 ms 5200 KB Output is correct
86 Correct 27 ms 5284 KB Output is correct
87 Correct 24 ms 5352 KB Output is correct
88 Correct 24 ms 5276 KB Output is correct
89 Correct 34 ms 5344 KB Output is correct
90 Correct 26 ms 5280 KB Output is correct
91 Correct 42 ms 10980 KB Output is correct
92 Correct 42 ms 10720 KB Output is correct
93 Correct 45 ms 9944 KB Output is correct
94 Correct 42 ms 10608 KB Output is correct
95 Correct 47 ms 10056 KB Output is correct
96 Correct 51 ms 13500 KB Output is correct
97 Correct 53 ms 13756 KB Output is correct
98 Correct 55 ms 14004 KB Output is correct
99 Correct 62 ms 12724 KB Output is correct
100 Correct 48 ms 13028 KB Output is correct
101 Correct 55 ms 13248 KB Output is correct
102 Correct 50 ms 14272 KB Output is correct
103 Correct 52 ms 12744 KB Output is correct
104 Correct 51 ms 12728 KB Output is correct
105 Correct 51 ms 13492 KB Output is correct
106 Correct 66 ms 13996 KB Output is correct
107 Correct 48 ms 14528 KB Output is correct
108 Correct 51 ms 14248 KB Output is correct
109 Correct 50 ms 13248 KB Output is correct
110 Correct 49 ms 13248 KB Output is correct
111 Correct 49 ms 12772 KB Output is correct
112 Correct 51 ms 13740 KB Output is correct
113 Correct 47 ms 13224 KB Output is correct
114 Correct 52 ms 12788 KB Output is correct
115 Correct 49 ms 12972 KB Output is correct
116 Execution timed out 7065 ms 1608 KB Time limit exceeded
117 Halted 0 ms 0 KB -