#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long N = 3e5 + 5;
long long a[N];
vector <long long> res;
long long cont (long long r) {
return (r + 1) * (r) / 2;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, q; cin >> n >> q;
map <ll, ll> ans, s;
for (ll i = 1; i <= n; i++) {
cin >> a[i];
s[a[i]] = -1;
ans[a[i]]++;
}
while (q--) {
ll l, r; cin >> l >> r;
for (auto it : ans) res.push_back(it.second);
ll h = 0;
sort(res.begin(), res.end());
vector <int> rs(res.size());
bool ok = 0;
int lt = 0, rt = rs.size() - 1;
for (auto it : res) {
if (ok) rs[rt] = it, rt--, ok = 0;
else rs[lt] = it, lt++, ok = 1;
} for (int i = 0; i < rs.size(); i++) res[i] = rs[i];
for (int i = 0; i < res.size(); i++) {
ll k = 2, nwres = res[i];
for (int j = i + 1; j < res.size(); j++) {
nwres += k * res[j], k++;
} h += nwres * res[i] - cont(res[i] - 1);
}
// while (next_permutation(res.begin(), res.end())) {
// ll x = 0;
// for (int i = 0; i < res.size(); i++) {
// ll k = 2, nwres = res[i];
// for (int j = i + 1; j < res.size(); j++) {
// nwres += k * res[j], k++;
// } x += nwres * res[i] - cont(res[i] - 1);
// } h = min(h, x);
// if (x == 93) {
// for (auto it : res) cout << it << ' ';
// cout << '\n';
// }
// }
cout << h << '\n';
}
return 0;
}
Compilation message
diversity.cpp: In function 'int main()':
diversity.cpp:31:29: 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 < rs.size(); i++) res[i] = rs[i];
| ~~^~~~~~~~~~~
diversity.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < res.size(); i++) {
| ~~^~~~~~~~~~~~
diversity.cpp:34:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int j = i + 1; j < res.size(); j++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1236 KB |
Output is correct |
5 |
Correct |
13 ms |
2268 KB |
Output is correct |
6 |
Correct |
21 ms |
3248 KB |
Output is correct |
7 |
Correct |
18 ms |
3236 KB |
Output is correct |
8 |
Correct |
20 ms |
3276 KB |
Output is correct |
9 |
Correct |
20 ms |
3284 KB |
Output is correct |
10 |
Correct |
20 ms |
3244 KB |
Output is correct |
11 |
Correct |
21 ms |
3284 KB |
Output is correct |
12 |
Correct |
21 ms |
3284 KB |
Output is correct |
13 |
Correct |
22 ms |
3224 KB |
Output is correct |
14 |
Correct |
23 ms |
3232 KB |
Output is correct |
15 |
Correct |
21 ms |
3188 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 |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1236 KB |
Output is correct |
5 |
Correct |
13 ms |
2268 KB |
Output is correct |
6 |
Correct |
21 ms |
3248 KB |
Output is correct |
7 |
Correct |
18 ms |
3236 KB |
Output is correct |
8 |
Correct |
20 ms |
3276 KB |
Output is correct |
9 |
Correct |
20 ms |
3284 KB |
Output is correct |
10 |
Correct |
20 ms |
3244 KB |
Output is correct |
11 |
Correct |
21 ms |
3284 KB |
Output is correct |
12 |
Correct |
21 ms |
3284 KB |
Output is correct |
13 |
Correct |
22 ms |
3224 KB |
Output is correct |
14 |
Correct |
23 ms |
3232 KB |
Output is correct |
15 |
Correct |
21 ms |
3188 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
1316 KB |
Output is correct |
20 |
Correct |
15 ms |
2384 KB |
Output is correct |
21 |
Correct |
22 ms |
3412 KB |
Output is correct |
22 |
Correct |
25 ms |
3392 KB |
Output is correct |
23 |
Correct |
22 ms |
3368 KB |
Output is correct |
24 |
Correct |
23 ms |
3404 KB |
Output is correct |
25 |
Correct |
23 ms |
3412 KB |
Output is correct |
26 |
Correct |
23 ms |
3404 KB |
Output is correct |
27 |
Correct |
26 ms |
3488 KB |
Output is correct |
28 |
Correct |
28 ms |
3388 KB |
Output is correct |
29 |
Correct |
25 ms |
3404 KB |
Output is correct |
30 |
Correct |
24 ms |
3400 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 |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1236 KB |
Output is correct |
5 |
Correct |
13 ms |
2268 KB |
Output is correct |
6 |
Correct |
21 ms |
3248 KB |
Output is correct |
7 |
Correct |
18 ms |
3236 KB |
Output is correct |
8 |
Correct |
20 ms |
3276 KB |
Output is correct |
9 |
Correct |
20 ms |
3284 KB |
Output is correct |
10 |
Correct |
20 ms |
3244 KB |
Output is correct |
11 |
Correct |
21 ms |
3284 KB |
Output is correct |
12 |
Correct |
21 ms |
3284 KB |
Output is correct |
13 |
Correct |
22 ms |
3224 KB |
Output is correct |
14 |
Correct |
23 ms |
3232 KB |
Output is correct |
15 |
Correct |
21 ms |
3188 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
1316 KB |
Output is correct |
20 |
Correct |
15 ms |
2384 KB |
Output is correct |
21 |
Correct |
22 ms |
3412 KB |
Output is correct |
22 |
Correct |
25 ms |
3392 KB |
Output is correct |
23 |
Correct |
22 ms |
3368 KB |
Output is correct |
24 |
Correct |
23 ms |
3404 KB |
Output is correct |
25 |
Correct |
23 ms |
3412 KB |
Output is correct |
26 |
Correct |
23 ms |
3404 KB |
Output is correct |
27 |
Correct |
26 ms |
3488 KB |
Output is correct |
28 |
Correct |
28 ms |
3388 KB |
Output is correct |
29 |
Correct |
25 ms |
3404 KB |
Output is correct |
30 |
Correct |
24 ms |
3400 KB |
Output is correct |
31 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
35 |
Correct |
3 ms |
472 KB |
Output is correct |
36 |
Correct |
3 ms |
472 KB |
Output is correct |
37 |
Correct |
7 ms |
1000 KB |
Output is correct |
38 |
Correct |
8 ms |
988 KB |
Output is correct |
39 |
Correct |
16 ms |
1632 KB |
Output is correct |
40 |
Correct |
30 ms |
2764 KB |
Output is correct |
41 |
Correct |
44 ms |
3888 KB |
Output is correct |
42 |
Correct |
45 ms |
3908 KB |
Output is correct |
43 |
Correct |
46 ms |
3852 KB |
Output is correct |
44 |
Correct |
46 ms |
3916 KB |
Output is correct |
45 |
Correct |
45 ms |
3828 KB |
Output is correct |
46 |
Correct |
46 ms |
3884 KB |
Output is correct |
47 |
Correct |
45 ms |
3904 KB |
Output is correct |
48 |
Correct |
44 ms |
3924 KB |
Output is correct |
49 |
Correct |
48 ms |
3840 KB |
Output is correct |
50 |
Correct |
48 ms |
3920 KB |
Output is correct |
51 |
Correct |
47 ms |
3928 KB |
Output is correct |
52 |
Correct |
44 ms |
3928 KB |
Output is correct |
53 |
Correct |
45 ms |
3904 KB |
Output is correct |
54 |
Correct |
53 ms |
3928 KB |
Output is correct |
55 |
Correct |
52 ms |
4000 KB |
Output is correct |
56 |
Correct |
48 ms |
3928 KB |
Output is correct |
57 |
Correct |
51 ms |
3872 KB |
Output is correct |
58 |
Correct |
47 ms |
3916 KB |
Output is correct |
59 |
Correct |
45 ms |
3916 KB |
Output is correct |
60 |
Correct |
48 ms |
3948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
1236 KB |
Output is correct |
15 |
Correct |
13 ms |
2268 KB |
Output is correct |
16 |
Correct |
21 ms |
3248 KB |
Output is correct |
17 |
Correct |
18 ms |
3236 KB |
Output is correct |
18 |
Correct |
20 ms |
3276 KB |
Output is correct |
19 |
Correct |
20 ms |
3284 KB |
Output is correct |
20 |
Correct |
20 ms |
3244 KB |
Output is correct |
21 |
Correct |
21 ms |
3284 KB |
Output is correct |
22 |
Correct |
21 ms |
3284 KB |
Output is correct |
23 |
Correct |
22 ms |
3224 KB |
Output is correct |
24 |
Correct |
23 ms |
3232 KB |
Output is correct |
25 |
Correct |
21 ms |
3188 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
8 ms |
1316 KB |
Output is correct |
30 |
Correct |
15 ms |
2384 KB |
Output is correct |
31 |
Correct |
22 ms |
3412 KB |
Output is correct |
32 |
Correct |
25 ms |
3392 KB |
Output is correct |
33 |
Correct |
22 ms |
3368 KB |
Output is correct |
34 |
Correct |
23 ms |
3404 KB |
Output is correct |
35 |
Correct |
23 ms |
3412 KB |
Output is correct |
36 |
Correct |
23 ms |
3404 KB |
Output is correct |
37 |
Correct |
26 ms |
3488 KB |
Output is correct |
38 |
Correct |
28 ms |
3388 KB |
Output is correct |
39 |
Correct |
25 ms |
3404 KB |
Output is correct |
40 |
Correct |
24 ms |
3400 KB |
Output is correct |
41 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
472 KB |
Output is correct |
46 |
Correct |
3 ms |
472 KB |
Output is correct |
47 |
Correct |
7 ms |
1000 KB |
Output is correct |
48 |
Correct |
8 ms |
988 KB |
Output is correct |
49 |
Correct |
16 ms |
1632 KB |
Output is correct |
50 |
Correct |
30 ms |
2764 KB |
Output is correct |
51 |
Correct |
44 ms |
3888 KB |
Output is correct |
52 |
Correct |
45 ms |
3908 KB |
Output is correct |
53 |
Correct |
46 ms |
3852 KB |
Output is correct |
54 |
Correct |
46 ms |
3916 KB |
Output is correct |
55 |
Correct |
45 ms |
3828 KB |
Output is correct |
56 |
Correct |
46 ms |
3884 KB |
Output is correct |
57 |
Correct |
45 ms |
3904 KB |
Output is correct |
58 |
Correct |
44 ms |
3924 KB |
Output is correct |
59 |
Correct |
48 ms |
3840 KB |
Output is correct |
60 |
Correct |
48 ms |
3920 KB |
Output is correct |
61 |
Correct |
47 ms |
3928 KB |
Output is correct |
62 |
Correct |
44 ms |
3928 KB |
Output is correct |
63 |
Correct |
45 ms |
3904 KB |
Output is correct |
64 |
Correct |
53 ms |
3928 KB |
Output is correct |
65 |
Correct |
52 ms |
4000 KB |
Output is correct |
66 |
Correct |
48 ms |
3928 KB |
Output is correct |
67 |
Correct |
51 ms |
3872 KB |
Output is correct |
68 |
Correct |
47 ms |
3916 KB |
Output is correct |
69 |
Correct |
45 ms |
3916 KB |
Output is correct |
70 |
Correct |
48 ms |
3948 KB |
Output is correct |
71 |
Correct |
12 ms |
1184 KB |
Output is correct |
72 |
Correct |
12 ms |
1108 KB |
Output is correct |
73 |
Correct |
11 ms |
1100 KB |
Output is correct |
74 |
Correct |
12 ms |
1108 KB |
Output is correct |
75 |
Correct |
12 ms |
1172 KB |
Output is correct |
76 |
Correct |
33 ms |
2228 KB |
Output is correct |
77 |
Correct |
35 ms |
2256 KB |
Output is correct |
78 |
Correct |
32 ms |
2260 KB |
Output is correct |
79 |
Correct |
32 ms |
2244 KB |
Output is correct |
80 |
Correct |
35 ms |
2264 KB |
Output is correct |
81 |
Correct |
90 ms |
4312 KB |
Output is correct |
82 |
Correct |
103 ms |
4248 KB |
Output is correct |
83 |
Correct |
101 ms |
4288 KB |
Output is correct |
84 |
Correct |
95 ms |
4224 KB |
Output is correct |
85 |
Correct |
89 ms |
4272 KB |
Output is correct |
86 |
Correct |
202 ms |
5788 KB |
Output is correct |
87 |
Correct |
214 ms |
5852 KB |
Output is correct |
88 |
Correct |
215 ms |
5820 KB |
Output is correct |
89 |
Correct |
210 ms |
5840 KB |
Output is correct |
90 |
Correct |
203 ms |
5772 KB |
Output is correct |
91 |
Correct |
3611 ms |
18048 KB |
Output is correct |
92 |
Correct |
3726 ms |
18056 KB |
Output is correct |
93 |
Correct |
3618 ms |
17996 KB |
Output is correct |
94 |
Correct |
3574 ms |
18072 KB |
Output is correct |
95 |
Correct |
3586 ms |
18036 KB |
Output is correct |
96 |
Execution timed out |
7062 ms |
31916 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
1236 KB |
Output is correct |
15 |
Correct |
13 ms |
2268 KB |
Output is correct |
16 |
Correct |
21 ms |
3248 KB |
Output is correct |
17 |
Correct |
18 ms |
3236 KB |
Output is correct |
18 |
Correct |
20 ms |
3276 KB |
Output is correct |
19 |
Correct |
20 ms |
3284 KB |
Output is correct |
20 |
Correct |
20 ms |
3244 KB |
Output is correct |
21 |
Correct |
21 ms |
3284 KB |
Output is correct |
22 |
Correct |
21 ms |
3284 KB |
Output is correct |
23 |
Correct |
22 ms |
3224 KB |
Output is correct |
24 |
Correct |
23 ms |
3232 KB |
Output is correct |
25 |
Correct |
21 ms |
3188 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
8 ms |
1316 KB |
Output is correct |
30 |
Correct |
15 ms |
2384 KB |
Output is correct |
31 |
Correct |
22 ms |
3412 KB |
Output is correct |
32 |
Correct |
25 ms |
3392 KB |
Output is correct |
33 |
Correct |
22 ms |
3368 KB |
Output is correct |
34 |
Correct |
23 ms |
3404 KB |
Output is correct |
35 |
Correct |
23 ms |
3412 KB |
Output is correct |
36 |
Correct |
23 ms |
3404 KB |
Output is correct |
37 |
Correct |
26 ms |
3488 KB |
Output is correct |
38 |
Correct |
28 ms |
3388 KB |
Output is correct |
39 |
Correct |
25 ms |
3404 KB |
Output is correct |
40 |
Correct |
24 ms |
3400 KB |
Output is correct |
41 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
472 KB |
Output is correct |
46 |
Correct |
3 ms |
472 KB |
Output is correct |
47 |
Correct |
7 ms |
1000 KB |
Output is correct |
48 |
Correct |
8 ms |
988 KB |
Output is correct |
49 |
Correct |
16 ms |
1632 KB |
Output is correct |
50 |
Correct |
30 ms |
2764 KB |
Output is correct |
51 |
Correct |
44 ms |
3888 KB |
Output is correct |
52 |
Correct |
45 ms |
3908 KB |
Output is correct |
53 |
Correct |
46 ms |
3852 KB |
Output is correct |
54 |
Correct |
46 ms |
3916 KB |
Output is correct |
55 |
Correct |
45 ms |
3828 KB |
Output is correct |
56 |
Correct |
46 ms |
3884 KB |
Output is correct |
57 |
Correct |
45 ms |
3904 KB |
Output is correct |
58 |
Correct |
44 ms |
3924 KB |
Output is correct |
59 |
Correct |
48 ms |
3840 KB |
Output is correct |
60 |
Correct |
48 ms |
3920 KB |
Output is correct |
61 |
Correct |
47 ms |
3928 KB |
Output is correct |
62 |
Correct |
44 ms |
3928 KB |
Output is correct |
63 |
Correct |
45 ms |
3904 KB |
Output is correct |
64 |
Correct |
53 ms |
3928 KB |
Output is correct |
65 |
Correct |
52 ms |
4000 KB |
Output is correct |
66 |
Correct |
48 ms |
3928 KB |
Output is correct |
67 |
Correct |
51 ms |
3872 KB |
Output is correct |
68 |
Correct |
47 ms |
3916 KB |
Output is correct |
69 |
Correct |
45 ms |
3916 KB |
Output is correct |
70 |
Correct |
48 ms |
3948 KB |
Output is correct |
71 |
Correct |
12 ms |
1184 KB |
Output is correct |
72 |
Correct |
12 ms |
1108 KB |
Output is correct |
73 |
Correct |
11 ms |
1100 KB |
Output is correct |
74 |
Correct |
12 ms |
1108 KB |
Output is correct |
75 |
Correct |
12 ms |
1172 KB |
Output is correct |
76 |
Correct |
33 ms |
2228 KB |
Output is correct |
77 |
Correct |
35 ms |
2256 KB |
Output is correct |
78 |
Correct |
32 ms |
2260 KB |
Output is correct |
79 |
Correct |
32 ms |
2244 KB |
Output is correct |
80 |
Correct |
35 ms |
2264 KB |
Output is correct |
81 |
Correct |
90 ms |
4312 KB |
Output is correct |
82 |
Correct |
103 ms |
4248 KB |
Output is correct |
83 |
Correct |
101 ms |
4288 KB |
Output is correct |
84 |
Correct |
95 ms |
4224 KB |
Output is correct |
85 |
Correct |
89 ms |
4272 KB |
Output is correct |
86 |
Correct |
202 ms |
5788 KB |
Output is correct |
87 |
Correct |
214 ms |
5852 KB |
Output is correct |
88 |
Correct |
215 ms |
5820 KB |
Output is correct |
89 |
Correct |
210 ms |
5840 KB |
Output is correct |
90 |
Correct |
203 ms |
5772 KB |
Output is correct |
91 |
Correct |
3611 ms |
18048 KB |
Output is correct |
92 |
Correct |
3726 ms |
18056 KB |
Output is correct |
93 |
Correct |
3618 ms |
17996 KB |
Output is correct |
94 |
Correct |
3574 ms |
18072 KB |
Output is correct |
95 |
Correct |
3586 ms |
18036 KB |
Output is correct |
96 |
Execution timed out |
7062 ms |
31916 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |