Submission #569710

# Submission time Handle Problem Language Result Execution time Memory
569710 2022-05-27T16:09:15 Z hoanghq2004 Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 17688 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3e5 + 10;

int n, q;
int a[N];

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    while (q--) {
        int L, R;
        cin >> L >> R;
        map <int, int> cnt;
        for (int i = L; i <= R; ++i) ++cnt[a[i]];
        vector <int> s;
        for (auto [_, __]: cnt) s.push_back(__);
        sort(s.begin(), s.end());
        vector <int> a;
        for (int i = 0; i < s.size(); ++i) if (i % 2 == 0) a.push_back(s[i]);
        for (int i = s.size() - 1; i >= 0; --i) if (i % 2 == 1) a.push_back(s[i]);
        int tot = (R - L + 1);
        long long ans = 0;
        int cur = 0;
        for (int i = 0; i < a.size(); ++i) {
            ans += 1LL * a[i] * (a[i] + 1) / 2;
            ans += 1LL * (cur + a[i]) * (tot - cur);
            ans -= 1LL * a[i] * a[i];
            cur += a[i];
        }
        cout << ans << '\n';
    }
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:28:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |         for (auto [_, __]: cnt) s.push_back(__);
      |                   ^
diversity.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int i = 0; i < s.size(); ++i) if (i % 2 == 0) a.push_back(s[i]);
      |                         ~~^~~~~~~~~~
diversity.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int i = 0; i < a.size(); ++i) {
      |                         ~~^~~~~~~~~~
# 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 0 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 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 1 ms 336 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 14 ms 1416 KB Output is correct
6 Correct 20 ms 2168 KB Output is correct
7 Correct 19 ms 2052 KB Output is correct
8 Correct 20 ms 2004 KB Output is correct
9 Correct 21 ms 2012 KB Output is correct
10 Correct 26 ms 2056 KB Output is correct
11 Correct 22 ms 2028 KB Output is correct
12 Correct 28 ms 2052 KB Output is correct
13 Correct 24 ms 2044 KB Output is correct
14 Correct 22 ms 2132 KB Output is correct
15 Correct 23 ms 2112 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 1 ms 336 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 14 ms 1416 KB Output is correct
6 Correct 20 ms 2168 KB Output is correct
7 Correct 19 ms 2052 KB Output is correct
8 Correct 20 ms 2004 KB Output is correct
9 Correct 21 ms 2012 KB Output is correct
10 Correct 26 ms 2056 KB Output is correct
11 Correct 22 ms 2028 KB Output is correct
12 Correct 28 ms 2052 KB Output is correct
13 Correct 24 ms 2044 KB Output is correct
14 Correct 22 ms 2132 KB Output is correct
15 Correct 23 ms 2112 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 8 ms 976 KB Output is correct
20 Correct 17 ms 1620 KB Output is correct
21 Correct 25 ms 2400 KB Output is correct
22 Correct 25 ms 2144 KB Output is correct
23 Correct 32 ms 2272 KB Output is correct
24 Correct 24 ms 2248 KB Output is correct
25 Correct 24 ms 2260 KB Output is correct
26 Correct 27 ms 2124 KB Output is correct
27 Correct 25 ms 2208 KB Output is correct
28 Correct 27 ms 2264 KB Output is correct
29 Correct 29 ms 2168 KB Output is correct
30 Correct 28 ms 2240 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 1 ms 336 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 14 ms 1416 KB Output is correct
6 Correct 20 ms 2168 KB Output is correct
7 Correct 19 ms 2052 KB Output is correct
8 Correct 20 ms 2004 KB Output is correct
9 Correct 21 ms 2012 KB Output is correct
10 Correct 26 ms 2056 KB Output is correct
11 Correct 22 ms 2028 KB Output is correct
12 Correct 28 ms 2052 KB Output is correct
13 Correct 24 ms 2044 KB Output is correct
14 Correct 22 ms 2132 KB Output is correct
15 Correct 23 ms 2112 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 8 ms 976 KB Output is correct
20 Correct 17 ms 1620 KB Output is correct
21 Correct 25 ms 2400 KB Output is correct
22 Correct 25 ms 2144 KB Output is correct
23 Correct 32 ms 2272 KB Output is correct
24 Correct 24 ms 2248 KB Output is correct
25 Correct 24 ms 2260 KB Output is correct
26 Correct 27 ms 2124 KB Output is correct
27 Correct 25 ms 2208 KB Output is correct
28 Correct 27 ms 2264 KB Output is correct
29 Correct 29 ms 2168 KB Output is correct
30 Correct 28 ms 2240 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 7 ms 724 KB Output is correct
38 Correct 9 ms 756 KB Output is correct
39 Correct 14 ms 1156 KB Output is correct
40 Correct 28 ms 1900 KB Output is correct
41 Correct 38 ms 2668 KB Output is correct
42 Correct 38 ms 2608 KB Output is correct
43 Correct 41 ms 2656 KB Output is correct
44 Correct 41 ms 2636 KB Output is correct
45 Correct 44 ms 2668 KB Output is correct
46 Correct 41 ms 2752 KB Output is correct
47 Correct 40 ms 2596 KB Output is correct
48 Correct 40 ms 2576 KB Output is correct
49 Correct 49 ms 2664 KB Output is correct
50 Correct 41 ms 2584 KB Output is correct
51 Correct 39 ms 2624 KB Output is correct
52 Correct 38 ms 2560 KB Output is correct
53 Correct 38 ms 2600 KB Output is correct
54 Correct 39 ms 2696 KB Output is correct
55 Correct 38 ms 2784 KB Output is correct
56 Correct 40 ms 2592 KB Output is correct
57 Correct 43 ms 2636 KB Output is correct
58 Correct 43 ms 2584 KB Output is correct
59 Correct 46 ms 2652 KB Output is correct
60 Correct 40 ms 2560 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 0 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 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 1 ms 336 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 14 ms 1416 KB Output is correct
16 Correct 20 ms 2168 KB Output is correct
17 Correct 19 ms 2052 KB Output is correct
18 Correct 20 ms 2004 KB Output is correct
19 Correct 21 ms 2012 KB Output is correct
20 Correct 26 ms 2056 KB Output is correct
21 Correct 22 ms 2028 KB Output is correct
22 Correct 28 ms 2052 KB Output is correct
23 Correct 24 ms 2044 KB Output is correct
24 Correct 22 ms 2132 KB Output is correct
25 Correct 23 ms 2112 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 8 ms 976 KB Output is correct
30 Correct 17 ms 1620 KB Output is correct
31 Correct 25 ms 2400 KB Output is correct
32 Correct 25 ms 2144 KB Output is correct
33 Correct 32 ms 2272 KB Output is correct
34 Correct 24 ms 2248 KB Output is correct
35 Correct 24 ms 2260 KB Output is correct
36 Correct 27 ms 2124 KB Output is correct
37 Correct 25 ms 2208 KB Output is correct
38 Correct 27 ms 2264 KB Output is correct
39 Correct 29 ms 2168 KB Output is correct
40 Correct 28 ms 2240 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 336 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 9 ms 756 KB Output is correct
49 Correct 14 ms 1156 KB Output is correct
50 Correct 28 ms 1900 KB Output is correct
51 Correct 38 ms 2668 KB Output is correct
52 Correct 38 ms 2608 KB Output is correct
53 Correct 41 ms 2656 KB Output is correct
54 Correct 41 ms 2636 KB Output is correct
55 Correct 44 ms 2668 KB Output is correct
56 Correct 41 ms 2752 KB Output is correct
57 Correct 40 ms 2596 KB Output is correct
58 Correct 40 ms 2576 KB Output is correct
59 Correct 49 ms 2664 KB Output is correct
60 Correct 41 ms 2584 KB Output is correct
61 Correct 39 ms 2624 KB Output is correct
62 Correct 38 ms 2560 KB Output is correct
63 Correct 38 ms 2600 KB Output is correct
64 Correct 39 ms 2696 KB Output is correct
65 Correct 38 ms 2784 KB Output is correct
66 Correct 40 ms 2592 KB Output is correct
67 Correct 43 ms 2636 KB Output is correct
68 Correct 43 ms 2584 KB Output is correct
69 Correct 46 ms 2652 KB Output is correct
70 Correct 40 ms 2560 KB Output is correct
71 Correct 9 ms 836 KB Output is correct
72 Correct 9 ms 832 KB Output is correct
73 Correct 9 ms 852 KB Output is correct
74 Correct 11 ms 836 KB Output is correct
75 Correct 9 ms 836 KB Output is correct
76 Correct 19 ms 1372 KB Output is correct
77 Correct 18 ms 1412 KB Output is correct
78 Correct 18 ms 1488 KB Output is correct
79 Correct 17 ms 1492 KB Output is correct
80 Correct 19 ms 1484 KB Output is correct
81 Correct 37 ms 2596 KB Output is correct
82 Correct 36 ms 2648 KB Output is correct
83 Correct 36 ms 2624 KB Output is correct
84 Correct 39 ms 2636 KB Output is correct
85 Correct 41 ms 2640 KB Output is correct
86 Correct 52 ms 3316 KB Output is correct
87 Correct 47 ms 3272 KB Output is correct
88 Correct 44 ms 3288 KB Output is correct
89 Correct 45 ms 3348 KB Output is correct
90 Correct 50 ms 3344 KB Output is correct
91 Correct 115 ms 9032 KB Output is correct
92 Correct 115 ms 9112 KB Output is correct
93 Correct 113 ms 9024 KB Output is correct
94 Correct 97 ms 9028 KB Output is correct
95 Correct 119 ms 8996 KB Output is correct
96 Correct 185 ms 14992 KB Output is correct
97 Correct 153 ms 15088 KB Output is correct
98 Correct 196 ms 15020 KB Output is correct
99 Correct 188 ms 15068 KB Output is correct
100 Correct 174 ms 14988 KB Output is correct
101 Correct 218 ms 14996 KB Output is correct
102 Correct 173 ms 15036 KB Output is correct
103 Correct 171 ms 15204 KB Output is correct
104 Correct 190 ms 15084 KB Output is correct
105 Correct 166 ms 15064 KB Output is correct
106 Correct 180 ms 17688 KB Output is correct
107 Correct 185 ms 17624 KB Output is correct
108 Correct 240 ms 17604 KB Output is correct
109 Correct 193 ms 17620 KB Output is correct
110 Correct 275 ms 17672 KB Output is correct
111 Correct 188 ms 17556 KB Output is correct
112 Correct 194 ms 17688 KB Output is correct
113 Correct 217 ms 17644 KB Output is correct
114 Correct 202 ms 17664 KB Output is correct
115 Correct 224 ms 17580 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 0 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 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 1 ms 336 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 14 ms 1416 KB Output is correct
16 Correct 20 ms 2168 KB Output is correct
17 Correct 19 ms 2052 KB Output is correct
18 Correct 20 ms 2004 KB Output is correct
19 Correct 21 ms 2012 KB Output is correct
20 Correct 26 ms 2056 KB Output is correct
21 Correct 22 ms 2028 KB Output is correct
22 Correct 28 ms 2052 KB Output is correct
23 Correct 24 ms 2044 KB Output is correct
24 Correct 22 ms 2132 KB Output is correct
25 Correct 23 ms 2112 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 8 ms 976 KB Output is correct
30 Correct 17 ms 1620 KB Output is correct
31 Correct 25 ms 2400 KB Output is correct
32 Correct 25 ms 2144 KB Output is correct
33 Correct 32 ms 2272 KB Output is correct
34 Correct 24 ms 2248 KB Output is correct
35 Correct 24 ms 2260 KB Output is correct
36 Correct 27 ms 2124 KB Output is correct
37 Correct 25 ms 2208 KB Output is correct
38 Correct 27 ms 2264 KB Output is correct
39 Correct 29 ms 2168 KB Output is correct
40 Correct 28 ms 2240 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 336 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 9 ms 756 KB Output is correct
49 Correct 14 ms 1156 KB Output is correct
50 Correct 28 ms 1900 KB Output is correct
51 Correct 38 ms 2668 KB Output is correct
52 Correct 38 ms 2608 KB Output is correct
53 Correct 41 ms 2656 KB Output is correct
54 Correct 41 ms 2636 KB Output is correct
55 Correct 44 ms 2668 KB Output is correct
56 Correct 41 ms 2752 KB Output is correct
57 Correct 40 ms 2596 KB Output is correct
58 Correct 40 ms 2576 KB Output is correct
59 Correct 49 ms 2664 KB Output is correct
60 Correct 41 ms 2584 KB Output is correct
61 Correct 39 ms 2624 KB Output is correct
62 Correct 38 ms 2560 KB Output is correct
63 Correct 38 ms 2600 KB Output is correct
64 Correct 39 ms 2696 KB Output is correct
65 Correct 38 ms 2784 KB Output is correct
66 Correct 40 ms 2592 KB Output is correct
67 Correct 43 ms 2636 KB Output is correct
68 Correct 43 ms 2584 KB Output is correct
69 Correct 46 ms 2652 KB Output is correct
70 Correct 40 ms 2560 KB Output is correct
71 Correct 9 ms 836 KB Output is correct
72 Correct 9 ms 832 KB Output is correct
73 Correct 9 ms 852 KB Output is correct
74 Correct 11 ms 836 KB Output is correct
75 Correct 9 ms 836 KB Output is correct
76 Correct 19 ms 1372 KB Output is correct
77 Correct 18 ms 1412 KB Output is correct
78 Correct 18 ms 1488 KB Output is correct
79 Correct 17 ms 1492 KB Output is correct
80 Correct 19 ms 1484 KB Output is correct
81 Correct 37 ms 2596 KB Output is correct
82 Correct 36 ms 2648 KB Output is correct
83 Correct 36 ms 2624 KB Output is correct
84 Correct 39 ms 2636 KB Output is correct
85 Correct 41 ms 2640 KB Output is correct
86 Correct 52 ms 3316 KB Output is correct
87 Correct 47 ms 3272 KB Output is correct
88 Correct 44 ms 3288 KB Output is correct
89 Correct 45 ms 3348 KB Output is correct
90 Correct 50 ms 3344 KB Output is correct
91 Correct 115 ms 9032 KB Output is correct
92 Correct 115 ms 9112 KB Output is correct
93 Correct 113 ms 9024 KB Output is correct
94 Correct 97 ms 9028 KB Output is correct
95 Correct 119 ms 8996 KB Output is correct
96 Correct 185 ms 14992 KB Output is correct
97 Correct 153 ms 15088 KB Output is correct
98 Correct 196 ms 15020 KB Output is correct
99 Correct 188 ms 15068 KB Output is correct
100 Correct 174 ms 14988 KB Output is correct
101 Correct 218 ms 14996 KB Output is correct
102 Correct 173 ms 15036 KB Output is correct
103 Correct 171 ms 15204 KB Output is correct
104 Correct 190 ms 15084 KB Output is correct
105 Correct 166 ms 15064 KB Output is correct
106 Correct 180 ms 17688 KB Output is correct
107 Correct 185 ms 17624 KB Output is correct
108 Correct 240 ms 17604 KB Output is correct
109 Correct 193 ms 17620 KB Output is correct
110 Correct 275 ms 17672 KB Output is correct
111 Correct 188 ms 17556 KB Output is correct
112 Correct 194 ms 17688 KB Output is correct
113 Correct 217 ms 17644 KB Output is correct
114 Correct 202 ms 17664 KB Output is correct
115 Correct 224 ms 17580 KB Output is correct
116 Correct 5675 ms 1480 KB Output is correct
117 Execution timed out 7032 ms 1268 KB Time limit exceeded
118 Halted 0 ms 0 KB -