Submission #799315

# Submission time Handle Problem Language Result Execution time Memory
799315 2023-07-31T12:33:00 Z Johann Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 8812 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;
    if (x == 1)
        sp.push_back(1);
    else
    {
        sp.push_back(x / 2);
        sp.push_back(x / 2);
        if (x & 1)
            sp.push_back(1);
    }
    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
            ll len = x * y;

            // if both are in set
            ans -= totalLengthOfSubsequences(len) - x * x * (totalLengthOfSubsequences(y) - y) - y * numberOfSubsequences(x);
            // if one is inside the other isn't
            ans -= (n - len) * (len * (len + 1) / 2 - x * y * (y + 1) / 2);
            // if both are outside
            ans -= (len - y) * left * (n - left - len);

            left += len;
            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 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 6 ms 1992 KB Output is correct
5 Correct 10 ms 3832 KB Output is correct
6 Correct 20 ms 5656 KB Output is correct
7 Correct 17 ms 5576 KB Output is correct
8 Correct 15 ms 5608 KB Output is correct
9 Correct 14 ms 5608 KB Output is correct
10 Correct 14 ms 5588 KB Output is correct
11 Correct 14 ms 5584 KB Output is correct
12 Correct 15 ms 5616 KB Output is correct
13 Correct 15 ms 5616 KB Output is correct
14 Correct 15 ms 5588 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 1 ms 320 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 6 ms 1992 KB Output is correct
5 Correct 10 ms 3832 KB Output is correct
6 Correct 20 ms 5656 KB Output is correct
7 Correct 17 ms 5576 KB Output is correct
8 Correct 15 ms 5608 KB Output is correct
9 Correct 14 ms 5608 KB Output is correct
10 Correct 14 ms 5588 KB Output is correct
11 Correct 14 ms 5584 KB Output is correct
12 Correct 15 ms 5616 KB Output is correct
13 Correct 15 ms 5616 KB Output is correct
14 Correct 15 ms 5588 KB Output is correct
15 Correct 14 ms 5616 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 8 ms 2080 KB Output is correct
20 Correct 11 ms 3932 KB Output is correct
21 Correct 18 ms 5860 KB Output is correct
22 Correct 15 ms 5716 KB Output is correct
23 Correct 15 ms 5780 KB Output is correct
24 Correct 16 ms 5728 KB Output is correct
25 Correct 15 ms 5716 KB Output is correct
26 Correct 15 ms 5716 KB Output is correct
27 Correct 21 ms 5772 KB Output is correct
28 Correct 19 ms 5716 KB Output is correct
29 Correct 16 ms 5728 KB Output is correct
30 Correct 18 ms 5828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 6 ms 1992 KB Output is correct
5 Correct 10 ms 3832 KB Output is correct
6 Correct 20 ms 5656 KB Output is correct
7 Correct 17 ms 5576 KB Output is correct
8 Correct 15 ms 5608 KB Output is correct
9 Correct 14 ms 5608 KB Output is correct
10 Correct 14 ms 5588 KB Output is correct
11 Correct 14 ms 5584 KB Output is correct
12 Correct 15 ms 5616 KB Output is correct
13 Correct 15 ms 5616 KB Output is correct
14 Correct 15 ms 5588 KB Output is correct
15 Correct 14 ms 5616 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 8 ms 2080 KB Output is correct
20 Correct 11 ms 3932 KB Output is correct
21 Correct 18 ms 5860 KB Output is correct
22 Correct 15 ms 5716 KB Output is correct
23 Correct 15 ms 5780 KB Output is correct
24 Correct 16 ms 5728 KB Output is correct
25 Correct 15 ms 5716 KB Output is correct
26 Correct 15 ms 5716 KB Output is correct
27 Correct 21 ms 5772 KB Output is correct
28 Correct 19 ms 5716 KB Output is correct
29 Correct 16 ms 5728 KB Output is correct
30 Correct 18 ms 5828 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 456 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 1236 KB Output is correct
38 Correct 4 ms 1304 KB Output is correct
39 Correct 6 ms 2260 KB Output is correct
40 Correct 11 ms 4184 KB Output is correct
41 Correct 16 ms 6116 KB Output is correct
42 Correct 16 ms 6116 KB Output is correct
43 Correct 17 ms 6228 KB Output is correct
44 Correct 17 ms 6112 KB Output is correct
45 Correct 17 ms 6116 KB Output is correct
46 Correct 16 ms 6120 KB Output is correct
47 Correct 18 ms 6228 KB Output is correct
48 Correct 19 ms 6120 KB Output is correct
49 Correct 16 ms 6116 KB Output is correct
50 Correct 16 ms 6112 KB Output is correct
51 Correct 16 ms 6120 KB Output is correct
52 Correct 17 ms 6096 KB Output is correct
53 Correct 21 ms 6112 KB Output is correct
54 Correct 16 ms 6220 KB Output is correct
55 Correct 18 ms 6112 KB Output is correct
56 Correct 16 ms 6120 KB Output is correct
57 Correct 17 ms 6108 KB Output is correct
58 Correct 16 ms 6216 KB Output is correct
59 Correct 17 ms 6116 KB Output is correct
60 Correct 17 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 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 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 6 ms 1992 KB Output is correct
15 Correct 10 ms 3832 KB Output is correct
16 Correct 20 ms 5656 KB Output is correct
17 Correct 17 ms 5576 KB Output is correct
18 Correct 15 ms 5608 KB Output is correct
19 Correct 14 ms 5608 KB Output is correct
20 Correct 14 ms 5588 KB Output is correct
21 Correct 14 ms 5584 KB Output is correct
22 Correct 15 ms 5616 KB Output is correct
23 Correct 15 ms 5616 KB Output is correct
24 Correct 15 ms 5588 KB Output is correct
25 Correct 14 ms 5616 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 8 ms 2080 KB Output is correct
30 Correct 11 ms 3932 KB Output is correct
31 Correct 18 ms 5860 KB Output is correct
32 Correct 15 ms 5716 KB Output is correct
33 Correct 15 ms 5780 KB Output is correct
34 Correct 16 ms 5728 KB Output is correct
35 Correct 15 ms 5716 KB Output is correct
36 Correct 15 ms 5716 KB Output is correct
37 Correct 21 ms 5772 KB Output is correct
38 Correct 19 ms 5716 KB Output is correct
39 Correct 16 ms 5728 KB Output is correct
40 Correct 18 ms 5828 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 456 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 4 ms 1304 KB Output is correct
49 Correct 6 ms 2260 KB Output is correct
50 Correct 11 ms 4184 KB Output is correct
51 Correct 16 ms 6116 KB Output is correct
52 Correct 16 ms 6116 KB Output is correct
53 Correct 17 ms 6228 KB Output is correct
54 Correct 17 ms 6112 KB Output is correct
55 Correct 17 ms 6116 KB Output is correct
56 Correct 16 ms 6120 KB Output is correct
57 Correct 18 ms 6228 KB Output is correct
58 Correct 19 ms 6120 KB Output is correct
59 Correct 16 ms 6116 KB Output is correct
60 Correct 16 ms 6112 KB Output is correct
61 Correct 16 ms 6120 KB Output is correct
62 Correct 17 ms 6096 KB Output is correct
63 Correct 21 ms 6112 KB Output is correct
64 Correct 16 ms 6220 KB Output is correct
65 Correct 18 ms 6112 KB Output is correct
66 Correct 16 ms 6120 KB Output is correct
67 Correct 17 ms 6108 KB Output is correct
68 Correct 16 ms 6216 KB Output is correct
69 Correct 17 ms 6116 KB Output is correct
70 Correct 17 ms 6100 KB Output is correct
71 Correct 4 ms 1364 KB Output is correct
72 Correct 3 ms 1360 KB Output is correct
73 Correct 4 ms 1356 KB Output is correct
74 Correct 4 ms 1236 KB Output is correct
75 Correct 4 ms 1356 KB Output is correct
76 Correct 8 ms 2388 KB Output is correct
77 Correct 7 ms 2388 KB Output is correct
78 Correct 7 ms 2388 KB Output is correct
79 Correct 7 ms 2380 KB Output is correct
80 Correct 6 ms 2380 KB Output is correct
81 Correct 12 ms 4436 KB Output is correct
82 Correct 17 ms 4440 KB Output is correct
83 Correct 12 ms 4460 KB Output is correct
84 Correct 13 ms 4444 KB Output is correct
85 Correct 13 ms 4428 KB Output is correct
86 Correct 14 ms 4700 KB Output is correct
87 Correct 14 ms 4632 KB Output is correct
88 Correct 15 ms 4564 KB Output is correct
89 Correct 17 ms 4560 KB Output is correct
90 Correct 14 ms 4696 KB Output is correct
91 Correct 21 ms 7520 KB Output is correct
92 Correct 22 ms 7520 KB Output is correct
93 Correct 22 ms 7516 KB Output is correct
94 Correct 28 ms 7520 KB Output is correct
95 Correct 21 ms 7508 KB Output is correct
96 Correct 25 ms 8396 KB Output is correct
97 Correct 24 ms 8416 KB Output is correct
98 Correct 29 ms 8412 KB Output is correct
99 Correct 35 ms 8420 KB Output is correct
100 Correct 24 ms 8420 KB Output is correct
101 Correct 24 ms 8412 KB Output is correct
102 Correct 24 ms 8424 KB Output is correct
103 Correct 24 ms 8424 KB Output is correct
104 Correct 24 ms 8424 KB Output is correct
105 Correct 24 ms 8428 KB Output is correct
106 Correct 24 ms 8804 KB Output is correct
107 Correct 24 ms 8788 KB Output is correct
108 Correct 24 ms 8812 KB Output is correct
109 Correct 23 ms 8788 KB Output is correct
110 Correct 24 ms 8808 KB Output is correct
111 Correct 24 ms 8800 KB Output is correct
112 Correct 24 ms 8804 KB Output is correct
113 Correct 30 ms 8804 KB Output is correct
114 Correct 24 ms 8812 KB Output is correct
115 Correct 23 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 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 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 6 ms 1992 KB Output is correct
15 Correct 10 ms 3832 KB Output is correct
16 Correct 20 ms 5656 KB Output is correct
17 Correct 17 ms 5576 KB Output is correct
18 Correct 15 ms 5608 KB Output is correct
19 Correct 14 ms 5608 KB Output is correct
20 Correct 14 ms 5588 KB Output is correct
21 Correct 14 ms 5584 KB Output is correct
22 Correct 15 ms 5616 KB Output is correct
23 Correct 15 ms 5616 KB Output is correct
24 Correct 15 ms 5588 KB Output is correct
25 Correct 14 ms 5616 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 8 ms 2080 KB Output is correct
30 Correct 11 ms 3932 KB Output is correct
31 Correct 18 ms 5860 KB Output is correct
32 Correct 15 ms 5716 KB Output is correct
33 Correct 15 ms 5780 KB Output is correct
34 Correct 16 ms 5728 KB Output is correct
35 Correct 15 ms 5716 KB Output is correct
36 Correct 15 ms 5716 KB Output is correct
37 Correct 21 ms 5772 KB Output is correct
38 Correct 19 ms 5716 KB Output is correct
39 Correct 16 ms 5728 KB Output is correct
40 Correct 18 ms 5828 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 456 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 4 ms 1304 KB Output is correct
49 Correct 6 ms 2260 KB Output is correct
50 Correct 11 ms 4184 KB Output is correct
51 Correct 16 ms 6116 KB Output is correct
52 Correct 16 ms 6116 KB Output is correct
53 Correct 17 ms 6228 KB Output is correct
54 Correct 17 ms 6112 KB Output is correct
55 Correct 17 ms 6116 KB Output is correct
56 Correct 16 ms 6120 KB Output is correct
57 Correct 18 ms 6228 KB Output is correct
58 Correct 19 ms 6120 KB Output is correct
59 Correct 16 ms 6116 KB Output is correct
60 Correct 16 ms 6112 KB Output is correct
61 Correct 16 ms 6120 KB Output is correct
62 Correct 17 ms 6096 KB Output is correct
63 Correct 21 ms 6112 KB Output is correct
64 Correct 16 ms 6220 KB Output is correct
65 Correct 18 ms 6112 KB Output is correct
66 Correct 16 ms 6120 KB Output is correct
67 Correct 17 ms 6108 KB Output is correct
68 Correct 16 ms 6216 KB Output is correct
69 Correct 17 ms 6116 KB Output is correct
70 Correct 17 ms 6100 KB Output is correct
71 Correct 4 ms 1364 KB Output is correct
72 Correct 3 ms 1360 KB Output is correct
73 Correct 4 ms 1356 KB Output is correct
74 Correct 4 ms 1236 KB Output is correct
75 Correct 4 ms 1356 KB Output is correct
76 Correct 8 ms 2388 KB Output is correct
77 Correct 7 ms 2388 KB Output is correct
78 Correct 7 ms 2388 KB Output is correct
79 Correct 7 ms 2380 KB Output is correct
80 Correct 6 ms 2380 KB Output is correct
81 Correct 12 ms 4436 KB Output is correct
82 Correct 17 ms 4440 KB Output is correct
83 Correct 12 ms 4460 KB Output is correct
84 Correct 13 ms 4444 KB Output is correct
85 Correct 13 ms 4428 KB Output is correct
86 Correct 14 ms 4700 KB Output is correct
87 Correct 14 ms 4632 KB Output is correct
88 Correct 15 ms 4564 KB Output is correct
89 Correct 17 ms 4560 KB Output is correct
90 Correct 14 ms 4696 KB Output is correct
91 Correct 21 ms 7520 KB Output is correct
92 Correct 22 ms 7520 KB Output is correct
93 Correct 22 ms 7516 KB Output is correct
94 Correct 28 ms 7520 KB Output is correct
95 Correct 21 ms 7508 KB Output is correct
96 Correct 25 ms 8396 KB Output is correct
97 Correct 24 ms 8416 KB Output is correct
98 Correct 29 ms 8412 KB Output is correct
99 Correct 35 ms 8420 KB Output is correct
100 Correct 24 ms 8420 KB Output is correct
101 Correct 24 ms 8412 KB Output is correct
102 Correct 24 ms 8424 KB Output is correct
103 Correct 24 ms 8424 KB Output is correct
104 Correct 24 ms 8424 KB Output is correct
105 Correct 24 ms 8428 KB Output is correct
106 Correct 24 ms 8804 KB Output is correct
107 Correct 24 ms 8788 KB Output is correct
108 Correct 24 ms 8812 KB Output is correct
109 Correct 23 ms 8788 KB Output is correct
110 Correct 24 ms 8808 KB Output is correct
111 Correct 24 ms 8800 KB Output is correct
112 Correct 24 ms 8804 KB Output is correct
113 Correct 30 ms 8804 KB Output is correct
114 Correct 24 ms 8812 KB Output is correct
115 Correct 23 ms 8796 KB Output is correct
116 Correct 581 ms 1552 KB Output is correct
117 Correct 790 ms 1672 KB Output is correct
118 Correct 2145 ms 3316 KB Output is correct
119 Correct 3111 ms 3272 KB Output is correct
120 Correct 3394 ms 3156 KB Output is correct
121 Correct 5556 ms 4756 KB Output is correct
122 Correct 6283 ms 4856 KB Output is correct
123 Execution timed out 7076 ms 8152 KB Time limit exceeded
124 Halted 0 ms 0 KB -