Submission #556004

# Submission time Handle Problem Language Result Execution time Memory
556004 2022-05-02T07:02:52 Z Stickfish Diversity (CEOI21_diversity) C++17
22 / 100
2431 ms 2344 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

const int MAXN = 3e5 + 123;
int a[MAXN];

signed main() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int t = 0; t < q; ++t) {
        int l, r;
        cin >> l >> r;
        --l;
        map<int, int> mp;
        for (int i = l; i < r; ++i)
            ++mp[a[i]];
        vector<int> cnts;
        for (auto [vl, cnt] : mp)
            cnts.push_back(cnt);
        sort(cnts.begin(), cnts.end());
        int m = cnts.size();
        ll ans = 1ll * n * n * n;
        for (int msk = 0; msk < (1 << (m - 1)); ++msk) {
            vector<int> arr;
            for (int i = 0; i < m; ++i) {
                if (msk & (1 << i))
                    arr.push_back(cnts[i]);
            }
            for (int i = m - 1; i >= 0; --i) {
                if ((msk & (1 << i)) == 0)
                    arr.push_back(cnts[i]);
            }
            ll ans0 = 0;
            for (int i = 0; i < m; ++i) {
                ans0 += 1ll * arr[i] * (arr[i] + 1) / 2;
                for (int j = i + 1; j < m; ++j) {
                    ans0 += 1ll * (j - i + 1) * arr[i] * arr[j];
                }
            }
            ans = min(ans, ans0);
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 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 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 16 ms 852 KB Output is correct
5 Correct 29 ms 1388 KB Output is correct
6 Correct 50 ms 2132 KB Output is correct
7 Correct 45 ms 2032 KB Output is correct
8 Correct 48 ms 1976 KB Output is correct
9 Correct 46 ms 2056 KB Output is correct
10 Correct 48 ms 2100 KB Output is correct
11 Correct 46 ms 2100 KB Output is correct
12 Correct 47 ms 2104 KB Output is correct
13 Correct 49 ms 1996 KB Output is correct
14 Correct 49 ms 2096 KB Output is correct
15 Correct 47 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 16 ms 852 KB Output is correct
5 Correct 29 ms 1388 KB Output is correct
6 Correct 50 ms 2132 KB Output is correct
7 Correct 45 ms 2032 KB Output is correct
8 Correct 48 ms 1976 KB Output is correct
9 Correct 46 ms 2056 KB Output is correct
10 Correct 48 ms 2100 KB Output is correct
11 Correct 46 ms 2100 KB Output is correct
12 Correct 47 ms 2104 KB Output is correct
13 Correct 49 ms 1996 KB Output is correct
14 Correct 49 ms 2096 KB Output is correct
15 Correct 47 ms 1996 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 6 ms 316 KB Output is correct
18 Correct 59 ms 352 KB Output is correct
19 Correct 264 ms 956 KB Output is correct
20 Correct 574 ms 1600 KB Output is correct
21 Correct 2416 ms 2280 KB Output is correct
22 Correct 2382 ms 2240 KB Output is correct
23 Correct 2431 ms 2256 KB Output is correct
24 Correct 2331 ms 2344 KB Output is correct
25 Correct 2344 ms 2232 KB Output is correct
26 Correct 2351 ms 2212 KB Output is correct
27 Correct 2393 ms 2240 KB Output is correct
28 Correct 2351 ms 2188 KB Output is correct
29 Correct 2368 ms 2200 KB Output is correct
30 Correct 2374 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 16 ms 852 KB Output is correct
5 Correct 29 ms 1388 KB Output is correct
6 Correct 50 ms 2132 KB Output is correct
7 Correct 45 ms 2032 KB Output is correct
8 Correct 48 ms 1976 KB Output is correct
9 Correct 46 ms 2056 KB Output is correct
10 Correct 48 ms 2100 KB Output is correct
11 Correct 46 ms 2100 KB Output is correct
12 Correct 47 ms 2104 KB Output is correct
13 Correct 49 ms 1996 KB Output is correct
14 Correct 49 ms 2096 KB Output is correct
15 Correct 47 ms 1996 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 6 ms 316 KB Output is correct
18 Correct 59 ms 352 KB Output is correct
19 Correct 264 ms 956 KB Output is correct
20 Correct 574 ms 1600 KB Output is correct
21 Correct 2416 ms 2280 KB Output is correct
22 Correct 2382 ms 2240 KB Output is correct
23 Correct 2431 ms 2256 KB Output is correct
24 Correct 2331 ms 2344 KB Output is correct
25 Correct 2344 ms 2232 KB Output is correct
26 Correct 2351 ms 2212 KB Output is correct
27 Correct 2393 ms 2240 KB Output is correct
28 Correct 2351 ms 2188 KB Output is correct
29 Correct 2368 ms 2200 KB Output is correct
30 Correct 2374 ms 2256 KB Output is correct
31 Incorrect 234 ms 312 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 852 KB Output is correct
15 Correct 29 ms 1388 KB Output is correct
16 Correct 50 ms 2132 KB Output is correct
17 Correct 45 ms 2032 KB Output is correct
18 Correct 48 ms 1976 KB Output is correct
19 Correct 46 ms 2056 KB Output is correct
20 Correct 48 ms 2100 KB Output is correct
21 Correct 46 ms 2100 KB Output is correct
22 Correct 47 ms 2104 KB Output is correct
23 Correct 49 ms 1996 KB Output is correct
24 Correct 49 ms 2096 KB Output is correct
25 Correct 47 ms 1996 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 6 ms 316 KB Output is correct
28 Correct 59 ms 352 KB Output is correct
29 Correct 264 ms 956 KB Output is correct
30 Correct 574 ms 1600 KB Output is correct
31 Correct 2416 ms 2280 KB Output is correct
32 Correct 2382 ms 2240 KB Output is correct
33 Correct 2431 ms 2256 KB Output is correct
34 Correct 2331 ms 2344 KB Output is correct
35 Correct 2344 ms 2232 KB Output is correct
36 Correct 2351 ms 2212 KB Output is correct
37 Correct 2393 ms 2240 KB Output is correct
38 Correct 2351 ms 2188 KB Output is correct
39 Correct 2368 ms 2200 KB Output is correct
40 Correct 2374 ms 2256 KB Output is correct
41 Incorrect 234 ms 312 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 852 KB Output is correct
15 Correct 29 ms 1388 KB Output is correct
16 Correct 50 ms 2132 KB Output is correct
17 Correct 45 ms 2032 KB Output is correct
18 Correct 48 ms 1976 KB Output is correct
19 Correct 46 ms 2056 KB Output is correct
20 Correct 48 ms 2100 KB Output is correct
21 Correct 46 ms 2100 KB Output is correct
22 Correct 47 ms 2104 KB Output is correct
23 Correct 49 ms 1996 KB Output is correct
24 Correct 49 ms 2096 KB Output is correct
25 Correct 47 ms 1996 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 6 ms 316 KB Output is correct
28 Correct 59 ms 352 KB Output is correct
29 Correct 264 ms 956 KB Output is correct
30 Correct 574 ms 1600 KB Output is correct
31 Correct 2416 ms 2280 KB Output is correct
32 Correct 2382 ms 2240 KB Output is correct
33 Correct 2431 ms 2256 KB Output is correct
34 Correct 2331 ms 2344 KB Output is correct
35 Correct 2344 ms 2232 KB Output is correct
36 Correct 2351 ms 2212 KB Output is correct
37 Correct 2393 ms 2240 KB Output is correct
38 Correct 2351 ms 2188 KB Output is correct
39 Correct 2368 ms 2200 KB Output is correct
40 Correct 2374 ms 2256 KB Output is correct
41 Incorrect 234 ms 312 KB Output isn't correct
42 Halted 0 ms 0 KB -