Submission #799255

# Submission time Handle Problem Language Result Execution time Memory
799255 2023-07-31T11:16:53 Z Johann Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 8900 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const ll INF = 1e18;
int N, Q;
vi A, AA;
ll ans;

vi split(int x)
{
    vi sp;
    int j = 0;
    while (2 * (1 << j) <= x)
    {
        sp.push_back(1 << j);
        x -= 1 << j;
        sp.push_back(1 << j);
        x -= 1 << j;
        ++j;
    }
    j = 0;
    while (x > 0)
    {
        if (x & (1 << j))
            sp.push_back(1 << j), x ^= 1 << j;
        ++j;
    }
    return sp;
}

ll numberOfSubsequences(ll n)
{
    return n * (n + 1) / 2;
}
ll totalLengthOfSubsequences(ll n)
{
    return n * (n + 1) * (n + 1) / 2 - (2 * n + 1) * (n + 1) * n / 6;
}

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

    cin >> N >> Q;
    AA.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> AA[i];

    while (Q--)
    {
        {
            int l, r;
            cin >> l >> r;
            --l;
            A = vi(AA.begin() + l, AA.begin() + r);
        }
        ll n = sz(A);

        vi heatMap(*max_element(all(A)) + 1, 0);
        for (int i = 0; i < sz(A); ++i)
            ++heatMap[A[i]];

        map<int, int> cnts;
        for (int i = 0; i < sz(heatMap); ++i)
            if (heatMap[i])
                ++cnts[heatMap[i]];

        vpii S;
        for (auto it = cnts.begin(); it != cnts.end(); ++it)
            for (int x : split(it->second))
                S.push_back({it->first, x});

        ll left = 0, right = 0;
        int num = sz(S);

        ans = totalLengthOfSubsequences(n);

        for (int j = 0; j < num; ++j)
        {

            ll x = S[j].first;  // how much
            ll y = S[j].second; // how often

            for (int i = 0; i < y; ++i)
            {
                // if both are in set
                ans += -totalLengthOfSubsequences(x) + numberOfSubsequences(x);
                // if on is inside the other isn't
                ans -= (x - 1) * x / 2 * (n - x);
                // if both are outside
                ans -= (x - 1) * left * (n - left - x);
                left += x;
                swap(left, right);
            }
        }
        cout << ans << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 5 ms 2004 KB Output is correct
5 Correct 9 ms 3788 KB Output is correct
6 Correct 15 ms 5608 KB Output is correct
7 Correct 14 ms 5604 KB Output is correct
8 Correct 14 ms 5588 KB Output is correct
9 Correct 14 ms 5612 KB Output is correct
10 Correct 15 ms 5644 KB Output is correct
11 Correct 18 ms 5588 KB Output is correct
12 Correct 19 ms 5576 KB Output is correct
13 Correct 14 ms 5632 KB Output is correct
14 Correct 20 ms 5624 KB Output is correct
15 Correct 14 ms 5616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 5 ms 2004 KB Output is correct
5 Correct 9 ms 3788 KB Output is correct
6 Correct 15 ms 5608 KB Output is correct
7 Correct 14 ms 5604 KB Output is correct
8 Correct 14 ms 5588 KB Output is correct
9 Correct 14 ms 5612 KB Output is correct
10 Correct 15 ms 5644 KB Output is correct
11 Correct 18 ms 5588 KB Output is correct
12 Correct 19 ms 5576 KB Output is correct
13 Correct 14 ms 5632 KB Output is correct
14 Correct 20 ms 5624 KB Output is correct
15 Correct 14 ms 5616 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 2132 KB Output is correct
20 Correct 12 ms 3932 KB Output is correct
21 Correct 16 ms 5840 KB Output is correct
22 Correct 15 ms 5716 KB Output is correct
23 Correct 15 ms 5736 KB Output is correct
24 Correct 17 ms 5792 KB Output is correct
25 Correct 15 ms 5676 KB Output is correct
26 Correct 15 ms 5708 KB Output is correct
27 Correct 15 ms 5716 KB Output is correct
28 Correct 15 ms 5720 KB Output is correct
29 Correct 20 ms 5716 KB Output is correct
30 Correct 18 ms 5728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 5 ms 2004 KB Output is correct
5 Correct 9 ms 3788 KB Output is correct
6 Correct 15 ms 5608 KB Output is correct
7 Correct 14 ms 5604 KB Output is correct
8 Correct 14 ms 5588 KB Output is correct
9 Correct 14 ms 5612 KB Output is correct
10 Correct 15 ms 5644 KB Output is correct
11 Correct 18 ms 5588 KB Output is correct
12 Correct 19 ms 5576 KB Output is correct
13 Correct 14 ms 5632 KB Output is correct
14 Correct 20 ms 5624 KB Output is correct
15 Correct 14 ms 5616 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 5 ms 2132 KB Output is correct
20 Correct 12 ms 3932 KB Output is correct
21 Correct 16 ms 5840 KB Output is correct
22 Correct 15 ms 5716 KB Output is correct
23 Correct 15 ms 5736 KB Output is correct
24 Correct 17 ms 5792 KB Output is correct
25 Correct 15 ms 5676 KB Output is correct
26 Correct 15 ms 5708 KB Output is correct
27 Correct 15 ms 5716 KB Output is correct
28 Correct 15 ms 5720 KB Output is correct
29 Correct 20 ms 5716 KB Output is correct
30 Correct 18 ms 5728 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 5 ms 1236 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 7 ms 2260 KB Output is correct
40 Correct 11 ms 4188 KB Output is correct
41 Correct 16 ms 6116 KB Output is correct
42 Correct 17 ms 6124 KB Output is correct
43 Correct 17 ms 6088 KB Output is correct
44 Correct 17 ms 6116 KB Output is correct
45 Correct 17 ms 6092 KB Output is correct
46 Correct 18 ms 6240 KB Output is correct
47 Correct 17 ms 6120 KB Output is correct
48 Correct 16 ms 6128 KB Output is correct
49 Correct 17 ms 6116 KB Output is correct
50 Correct 17 ms 6112 KB Output is correct
51 Correct 17 ms 6112 KB Output is correct
52 Correct 22 ms 6108 KB Output is correct
53 Correct 17 ms 6228 KB Output is correct
54 Correct 17 ms 6120 KB Output is correct
55 Correct 17 ms 6228 KB Output is correct
56 Correct 19 ms 6124 KB Output is correct
57 Correct 18 ms 6120 KB Output is correct
58 Correct 17 ms 6208 KB Output is correct
59 Correct 17 ms 6116 KB Output is correct
60 Correct 17 ms 6116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 2004 KB Output is correct
15 Correct 9 ms 3788 KB Output is correct
16 Correct 15 ms 5608 KB Output is correct
17 Correct 14 ms 5604 KB Output is correct
18 Correct 14 ms 5588 KB Output is correct
19 Correct 14 ms 5612 KB Output is correct
20 Correct 15 ms 5644 KB Output is correct
21 Correct 18 ms 5588 KB Output is correct
22 Correct 19 ms 5576 KB Output is correct
23 Correct 14 ms 5632 KB Output is correct
24 Correct 20 ms 5624 KB Output is correct
25 Correct 14 ms 5616 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 316 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 5 ms 2132 KB Output is correct
30 Correct 12 ms 3932 KB Output is correct
31 Correct 16 ms 5840 KB Output is correct
32 Correct 15 ms 5716 KB Output is correct
33 Correct 15 ms 5736 KB Output is correct
34 Correct 17 ms 5792 KB Output is correct
35 Correct 15 ms 5676 KB Output is correct
36 Correct 15 ms 5708 KB Output is correct
37 Correct 15 ms 5716 KB Output is correct
38 Correct 15 ms 5720 KB Output is correct
39 Correct 20 ms 5716 KB Output is correct
40 Correct 18 ms 5728 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 5 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 7 ms 2260 KB Output is correct
50 Correct 11 ms 4188 KB Output is correct
51 Correct 16 ms 6116 KB Output is correct
52 Correct 17 ms 6124 KB Output is correct
53 Correct 17 ms 6088 KB Output is correct
54 Correct 17 ms 6116 KB Output is correct
55 Correct 17 ms 6092 KB Output is correct
56 Correct 18 ms 6240 KB Output is correct
57 Correct 17 ms 6120 KB Output is correct
58 Correct 16 ms 6128 KB Output is correct
59 Correct 17 ms 6116 KB Output is correct
60 Correct 17 ms 6112 KB Output is correct
61 Correct 17 ms 6112 KB Output is correct
62 Correct 22 ms 6108 KB Output is correct
63 Correct 17 ms 6228 KB Output is correct
64 Correct 17 ms 6120 KB Output is correct
65 Correct 17 ms 6228 KB Output is correct
66 Correct 19 ms 6124 KB Output is correct
67 Correct 18 ms 6120 KB Output is correct
68 Correct 17 ms 6208 KB Output is correct
69 Correct 17 ms 6116 KB Output is correct
70 Correct 17 ms 6116 KB Output is correct
71 Correct 4 ms 1352 KB Output is correct
72 Correct 4 ms 1364 KB Output is correct
73 Correct 3 ms 1364 KB Output is correct
74 Correct 4 ms 1356 KB Output is correct
75 Correct 3 ms 1356 KB Output is correct
76 Correct 7 ms 2388 KB Output is correct
77 Correct 6 ms 2384 KB Output is correct
78 Correct 6 ms 2388 KB Output is correct
79 Correct 6 ms 2376 KB Output is correct
80 Correct 6 ms 2348 KB Output is correct
81 Correct 13 ms 4516 KB Output is correct
82 Correct 13 ms 4428 KB Output is correct
83 Correct 13 ms 4444 KB Output is correct
84 Correct 13 ms 4504 KB Output is correct
85 Correct 13 ms 4436 KB Output is correct
86 Correct 14 ms 4692 KB Output is correct
87 Correct 14 ms 4704 KB Output is correct
88 Correct 14 ms 4704 KB Output is correct
89 Correct 14 ms 4628 KB Output is correct
90 Correct 14 ms 4620 KB Output is correct
91 Correct 22 ms 7520 KB Output is correct
92 Correct 25 ms 7500 KB Output is correct
93 Correct 21 ms 7472 KB Output is correct
94 Correct 21 ms 7524 KB Output is correct
95 Correct 21 ms 7428 KB Output is correct
96 Correct 24 ms 8424 KB Output is correct
97 Correct 24 ms 8416 KB Output is correct
98 Correct 25 ms 8416 KB Output is correct
99 Correct 23 ms 8464 KB Output is correct
100 Correct 23 ms 8416 KB Output is correct
101 Correct 25 ms 8400 KB Output is correct
102 Correct 24 ms 8448 KB Output is correct
103 Correct 24 ms 8404 KB Output is correct
104 Correct 24 ms 8420 KB Output is correct
105 Correct 25 ms 8404 KB Output is correct
106 Correct 23 ms 8804 KB Output is correct
107 Correct 23 ms 8800 KB Output is correct
108 Correct 23 ms 8796 KB Output is correct
109 Correct 24 ms 8804 KB Output is correct
110 Correct 28 ms 8804 KB Output is correct
111 Correct 24 ms 8796 KB Output is correct
112 Correct 23 ms 8808 KB Output is correct
113 Correct 24 ms 8804 KB Output is correct
114 Correct 23 ms 8900 KB Output is correct
115 Correct 23 ms 8784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 5 ms 2004 KB Output is correct
15 Correct 9 ms 3788 KB Output is correct
16 Correct 15 ms 5608 KB Output is correct
17 Correct 14 ms 5604 KB Output is correct
18 Correct 14 ms 5588 KB Output is correct
19 Correct 14 ms 5612 KB Output is correct
20 Correct 15 ms 5644 KB Output is correct
21 Correct 18 ms 5588 KB Output is correct
22 Correct 19 ms 5576 KB Output is correct
23 Correct 14 ms 5632 KB Output is correct
24 Correct 20 ms 5624 KB Output is correct
25 Correct 14 ms 5616 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 316 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 5 ms 2132 KB Output is correct
30 Correct 12 ms 3932 KB Output is correct
31 Correct 16 ms 5840 KB Output is correct
32 Correct 15 ms 5716 KB Output is correct
33 Correct 15 ms 5736 KB Output is correct
34 Correct 17 ms 5792 KB Output is correct
35 Correct 15 ms 5676 KB Output is correct
36 Correct 15 ms 5708 KB Output is correct
37 Correct 15 ms 5716 KB Output is correct
38 Correct 15 ms 5720 KB Output is correct
39 Correct 20 ms 5716 KB Output is correct
40 Correct 18 ms 5728 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 5 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 7 ms 2260 KB Output is correct
50 Correct 11 ms 4188 KB Output is correct
51 Correct 16 ms 6116 KB Output is correct
52 Correct 17 ms 6124 KB Output is correct
53 Correct 17 ms 6088 KB Output is correct
54 Correct 17 ms 6116 KB Output is correct
55 Correct 17 ms 6092 KB Output is correct
56 Correct 18 ms 6240 KB Output is correct
57 Correct 17 ms 6120 KB Output is correct
58 Correct 16 ms 6128 KB Output is correct
59 Correct 17 ms 6116 KB Output is correct
60 Correct 17 ms 6112 KB Output is correct
61 Correct 17 ms 6112 KB Output is correct
62 Correct 22 ms 6108 KB Output is correct
63 Correct 17 ms 6228 KB Output is correct
64 Correct 17 ms 6120 KB Output is correct
65 Correct 17 ms 6228 KB Output is correct
66 Correct 19 ms 6124 KB Output is correct
67 Correct 18 ms 6120 KB Output is correct
68 Correct 17 ms 6208 KB Output is correct
69 Correct 17 ms 6116 KB Output is correct
70 Correct 17 ms 6116 KB Output is correct
71 Correct 4 ms 1352 KB Output is correct
72 Correct 4 ms 1364 KB Output is correct
73 Correct 3 ms 1364 KB Output is correct
74 Correct 4 ms 1356 KB Output is correct
75 Correct 3 ms 1356 KB Output is correct
76 Correct 7 ms 2388 KB Output is correct
77 Correct 6 ms 2384 KB Output is correct
78 Correct 6 ms 2388 KB Output is correct
79 Correct 6 ms 2376 KB Output is correct
80 Correct 6 ms 2348 KB Output is correct
81 Correct 13 ms 4516 KB Output is correct
82 Correct 13 ms 4428 KB Output is correct
83 Correct 13 ms 4444 KB Output is correct
84 Correct 13 ms 4504 KB Output is correct
85 Correct 13 ms 4436 KB Output is correct
86 Correct 14 ms 4692 KB Output is correct
87 Correct 14 ms 4704 KB Output is correct
88 Correct 14 ms 4704 KB Output is correct
89 Correct 14 ms 4628 KB Output is correct
90 Correct 14 ms 4620 KB Output is correct
91 Correct 22 ms 7520 KB Output is correct
92 Correct 25 ms 7500 KB Output is correct
93 Correct 21 ms 7472 KB Output is correct
94 Correct 21 ms 7524 KB Output is correct
95 Correct 21 ms 7428 KB Output is correct
96 Correct 24 ms 8424 KB Output is correct
97 Correct 24 ms 8416 KB Output is correct
98 Correct 25 ms 8416 KB Output is correct
99 Correct 23 ms 8464 KB Output is correct
100 Correct 23 ms 8416 KB Output is correct
101 Correct 25 ms 8400 KB Output is correct
102 Correct 24 ms 8448 KB Output is correct
103 Correct 24 ms 8404 KB Output is correct
104 Correct 24 ms 8420 KB Output is correct
105 Correct 25 ms 8404 KB Output is correct
106 Correct 23 ms 8804 KB Output is correct
107 Correct 23 ms 8800 KB Output is correct
108 Correct 23 ms 8796 KB Output is correct
109 Correct 24 ms 8804 KB Output is correct
110 Correct 28 ms 8804 KB Output is correct
111 Correct 24 ms 8796 KB Output is correct
112 Correct 23 ms 8808 KB Output is correct
113 Correct 24 ms 8804 KB Output is correct
114 Correct 23 ms 8900 KB Output is correct
115 Correct 23 ms 8784 KB Output is correct
116 Correct 627 ms 1560 KB Output is correct
117 Correct 805 ms 1564 KB Output is correct
118 Correct 2227 ms 3076 KB Output is correct
119 Correct 3307 ms 3104 KB Output is correct
120 Correct 3717 ms 3108 KB Output is correct
121 Correct 5814 ms 4744 KB Output is correct
122 Correct 6760 ms 4716 KB Output is correct
123 Execution timed out 7060 ms 8056 KB Time limit exceeded
124 Halted 0 ms 0 KB -