#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a[300005],fr[300005],q,l1,r1;
signed main()
{
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i],fr[a[i]]++;
cin >> l1 >> r1;
vector<int> poz_fr;
for (int i = 1; i <= 300000; i++)
if (fr[i] > 0)
poz_fr.push_back(fr[i]);
sort(poz_fr.begin(),poz_fr.end());
vector<int> v(poz_fr.size());
l1 = 0,r1 = poz_fr.size() - 1;
for (int i = 0; i < poz_fr.size(); i++)
{
if (i % 2 == 0)
v[l1] = poz_fr[i],l1++;
else
v[r1] = poz_fr[i],r1--;
}
int ans = 0;
for (int i = 0; i < v.size(); i++)
ans += v[i] * (v[i] + 1) / 2;
for (int i = 0; i < v.size(); i++)
for (int j = i + 1; j < v.size(); j++)
ans += (j - i + 1) * v[i] * v[j];
cout << ans;
return 0;
}
Compilation message
diversity.cpp: In function 'int main()':
diversity.cpp:22:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < poz_fr.size(); i++)
| ~~^~~~~~~~~~~~~~~
diversity.cpp:30:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
diversity.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
diversity.cpp:33:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int j = i + 1; j < v.size(); j++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
17 ms |
2248 KB |
Output is correct |
6 |
Correct |
28 ms |
3256 KB |
Output is correct |
7 |
Correct |
25 ms |
3212 KB |
Output is correct |
8 |
Correct |
26 ms |
3420 KB |
Output is correct |
9 |
Correct |
26 ms |
3152 KB |
Output is correct |
10 |
Correct |
27 ms |
3420 KB |
Output is correct |
11 |
Correct |
26 ms |
3416 KB |
Output is correct |
12 |
Correct |
35 ms |
3416 KB |
Output is correct |
13 |
Correct |
43 ms |
3420 KB |
Output is correct |
14 |
Correct |
26 ms |
3156 KB |
Output is correct |
15 |
Correct |
25 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
17 ms |
2248 KB |
Output is correct |
6 |
Correct |
28 ms |
3256 KB |
Output is correct |
7 |
Correct |
25 ms |
3212 KB |
Output is correct |
8 |
Correct |
26 ms |
3420 KB |
Output is correct |
9 |
Correct |
26 ms |
3152 KB |
Output is correct |
10 |
Correct |
27 ms |
3420 KB |
Output is correct |
11 |
Correct |
26 ms |
3416 KB |
Output is correct |
12 |
Correct |
35 ms |
3416 KB |
Output is correct |
13 |
Correct |
43 ms |
3420 KB |
Output is correct |
14 |
Correct |
26 ms |
3156 KB |
Output is correct |
15 |
Correct |
25 ms |
3156 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
11 ms |
1448 KB |
Output is correct |
20 |
Correct |
19 ms |
2396 KB |
Output is correct |
21 |
Correct |
30 ms |
3460 KB |
Output is correct |
22 |
Correct |
31 ms |
3440 KB |
Output is correct |
23 |
Correct |
29 ms |
3412 KB |
Output is correct |
24 |
Correct |
38 ms |
3420 KB |
Output is correct |
25 |
Correct |
29 ms |
3524 KB |
Output is correct |
26 |
Correct |
30 ms |
3288 KB |
Output is correct |
27 |
Correct |
29 ms |
3420 KB |
Output is correct |
28 |
Correct |
31 ms |
3400 KB |
Output is correct |
29 |
Correct |
30 ms |
3472 KB |
Output is correct |
30 |
Correct |
29 ms |
3392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
17 ms |
2248 KB |
Output is correct |
6 |
Correct |
28 ms |
3256 KB |
Output is correct |
7 |
Correct |
25 ms |
3212 KB |
Output is correct |
8 |
Correct |
26 ms |
3420 KB |
Output is correct |
9 |
Correct |
26 ms |
3152 KB |
Output is correct |
10 |
Correct |
27 ms |
3420 KB |
Output is correct |
11 |
Correct |
26 ms |
3416 KB |
Output is correct |
12 |
Correct |
35 ms |
3416 KB |
Output is correct |
13 |
Correct |
43 ms |
3420 KB |
Output is correct |
14 |
Correct |
26 ms |
3156 KB |
Output is correct |
15 |
Correct |
25 ms |
3156 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
11 ms |
1448 KB |
Output is correct |
20 |
Correct |
19 ms |
2396 KB |
Output is correct |
21 |
Correct |
30 ms |
3460 KB |
Output is correct |
22 |
Correct |
31 ms |
3440 KB |
Output is correct |
23 |
Correct |
29 ms |
3412 KB |
Output is correct |
24 |
Correct |
38 ms |
3420 KB |
Output is correct |
25 |
Correct |
29 ms |
3524 KB |
Output is correct |
26 |
Correct |
30 ms |
3288 KB |
Output is correct |
27 |
Correct |
29 ms |
3420 KB |
Output is correct |
28 |
Correct |
31 ms |
3400 KB |
Output is correct |
29 |
Correct |
30 ms |
3472 KB |
Output is correct |
30 |
Correct |
29 ms |
3392 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
536 KB |
Output is correct |
37 |
Correct |
7 ms |
856 KB |
Output is correct |
38 |
Correct |
7 ms |
860 KB |
Output is correct |
39 |
Correct |
12 ms |
1628 KB |
Output is correct |
40 |
Correct |
24 ms |
2652 KB |
Output is correct |
41 |
Correct |
36 ms |
3928 KB |
Output is correct |
42 |
Correct |
37 ms |
3924 KB |
Output is correct |
43 |
Correct |
35 ms |
3924 KB |
Output is correct |
44 |
Correct |
35 ms |
3712 KB |
Output is correct |
45 |
Correct |
35 ms |
3924 KB |
Output is correct |
46 |
Correct |
35 ms |
3924 KB |
Output is correct |
47 |
Correct |
35 ms |
3880 KB |
Output is correct |
48 |
Correct |
35 ms |
3932 KB |
Output is correct |
49 |
Correct |
35 ms |
3920 KB |
Output is correct |
50 |
Correct |
36 ms |
3836 KB |
Output is correct |
51 |
Correct |
35 ms |
3920 KB |
Output is correct |
52 |
Correct |
41 ms |
3924 KB |
Output is correct |
53 |
Correct |
35 ms |
3920 KB |
Output is correct |
54 |
Correct |
37 ms |
3920 KB |
Output is correct |
55 |
Correct |
36 ms |
3920 KB |
Output is correct |
56 |
Correct |
38 ms |
3924 KB |
Output is correct |
57 |
Correct |
35 ms |
3932 KB |
Output is correct |
58 |
Correct |
36 ms |
3920 KB |
Output is correct |
59 |
Correct |
35 ms |
3920 KB |
Output is correct |
60 |
Correct |
38 ms |
3936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
9 ms |
1372 KB |
Output is correct |
15 |
Correct |
17 ms |
2248 KB |
Output is correct |
16 |
Correct |
28 ms |
3256 KB |
Output is correct |
17 |
Correct |
25 ms |
3212 KB |
Output is correct |
18 |
Correct |
26 ms |
3420 KB |
Output is correct |
19 |
Correct |
26 ms |
3152 KB |
Output is correct |
20 |
Correct |
27 ms |
3420 KB |
Output is correct |
21 |
Correct |
26 ms |
3416 KB |
Output is correct |
22 |
Correct |
35 ms |
3416 KB |
Output is correct |
23 |
Correct |
43 ms |
3420 KB |
Output is correct |
24 |
Correct |
26 ms |
3156 KB |
Output is correct |
25 |
Correct |
25 ms |
3156 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
444 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
11 ms |
1448 KB |
Output is correct |
30 |
Correct |
19 ms |
2396 KB |
Output is correct |
31 |
Correct |
30 ms |
3460 KB |
Output is correct |
32 |
Correct |
31 ms |
3440 KB |
Output is correct |
33 |
Correct |
29 ms |
3412 KB |
Output is correct |
34 |
Correct |
38 ms |
3420 KB |
Output is correct |
35 |
Correct |
29 ms |
3524 KB |
Output is correct |
36 |
Correct |
30 ms |
3288 KB |
Output is correct |
37 |
Correct |
29 ms |
3420 KB |
Output is correct |
38 |
Correct |
31 ms |
3400 KB |
Output is correct |
39 |
Correct |
30 ms |
3472 KB |
Output is correct |
40 |
Correct |
29 ms |
3392 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
536 KB |
Output is correct |
47 |
Correct |
7 ms |
856 KB |
Output is correct |
48 |
Correct |
7 ms |
860 KB |
Output is correct |
49 |
Correct |
12 ms |
1628 KB |
Output is correct |
50 |
Correct |
24 ms |
2652 KB |
Output is correct |
51 |
Correct |
36 ms |
3928 KB |
Output is correct |
52 |
Correct |
37 ms |
3924 KB |
Output is correct |
53 |
Correct |
35 ms |
3924 KB |
Output is correct |
54 |
Correct |
35 ms |
3712 KB |
Output is correct |
55 |
Correct |
35 ms |
3924 KB |
Output is correct |
56 |
Correct |
35 ms |
3924 KB |
Output is correct |
57 |
Correct |
35 ms |
3880 KB |
Output is correct |
58 |
Correct |
35 ms |
3932 KB |
Output is correct |
59 |
Correct |
35 ms |
3920 KB |
Output is correct |
60 |
Correct |
36 ms |
3836 KB |
Output is correct |
61 |
Correct |
35 ms |
3920 KB |
Output is correct |
62 |
Correct |
41 ms |
3924 KB |
Output is correct |
63 |
Correct |
35 ms |
3920 KB |
Output is correct |
64 |
Correct |
37 ms |
3920 KB |
Output is correct |
65 |
Correct |
36 ms |
3920 KB |
Output is correct |
66 |
Correct |
38 ms |
3924 KB |
Output is correct |
67 |
Correct |
35 ms |
3932 KB |
Output is correct |
68 |
Correct |
36 ms |
3920 KB |
Output is correct |
69 |
Correct |
35 ms |
3920 KB |
Output is correct |
70 |
Correct |
38 ms |
3936 KB |
Output is correct |
71 |
Correct |
8 ms |
1112 KB |
Output is correct |
72 |
Correct |
8 ms |
1116 KB |
Output is correct |
73 |
Correct |
8 ms |
968 KB |
Output is correct |
74 |
Correct |
8 ms |
1116 KB |
Output is correct |
75 |
Correct |
8 ms |
1116 KB |
Output is correct |
76 |
Correct |
18 ms |
1628 KB |
Output is correct |
77 |
Correct |
18 ms |
1852 KB |
Output is correct |
78 |
Correct |
22 ms |
1624 KB |
Output is correct |
79 |
Correct |
19 ms |
1624 KB |
Output is correct |
80 |
Correct |
19 ms |
1636 KB |
Output is correct |
81 |
Correct |
47 ms |
3160 KB |
Output is correct |
82 |
Correct |
45 ms |
3152 KB |
Output is correct |
83 |
Correct |
45 ms |
3164 KB |
Output is correct |
84 |
Correct |
45 ms |
3160 KB |
Output is correct |
85 |
Correct |
42 ms |
3160 KB |
Output is correct |
86 |
Correct |
100 ms |
3672 KB |
Output is correct |
87 |
Correct |
100 ms |
3544 KB |
Output is correct |
88 |
Correct |
100 ms |
3528 KB |
Output is correct |
89 |
Correct |
105 ms |
3536 KB |
Output is correct |
90 |
Correct |
102 ms |
3544 KB |
Output is correct |
91 |
Correct |
1851 ms |
6852 KB |
Output is correct |
92 |
Correct |
1751 ms |
6856 KB |
Output is correct |
93 |
Correct |
1784 ms |
6852 KB |
Output is correct |
94 |
Correct |
1770 ms |
6864 KB |
Output is correct |
95 |
Correct |
1615 ms |
6852 KB |
Output is correct |
96 |
Correct |
6997 ms |
9408 KB |
Output is correct |
97 |
Correct |
6792 ms |
9408 KB |
Output is correct |
98 |
Execution timed out |
7067 ms |
9412 KB |
Time limit exceeded |
99 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
9 ms |
1372 KB |
Output is correct |
15 |
Correct |
17 ms |
2248 KB |
Output is correct |
16 |
Correct |
28 ms |
3256 KB |
Output is correct |
17 |
Correct |
25 ms |
3212 KB |
Output is correct |
18 |
Correct |
26 ms |
3420 KB |
Output is correct |
19 |
Correct |
26 ms |
3152 KB |
Output is correct |
20 |
Correct |
27 ms |
3420 KB |
Output is correct |
21 |
Correct |
26 ms |
3416 KB |
Output is correct |
22 |
Correct |
35 ms |
3416 KB |
Output is correct |
23 |
Correct |
43 ms |
3420 KB |
Output is correct |
24 |
Correct |
26 ms |
3156 KB |
Output is correct |
25 |
Correct |
25 ms |
3156 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
444 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
11 ms |
1448 KB |
Output is correct |
30 |
Correct |
19 ms |
2396 KB |
Output is correct |
31 |
Correct |
30 ms |
3460 KB |
Output is correct |
32 |
Correct |
31 ms |
3440 KB |
Output is correct |
33 |
Correct |
29 ms |
3412 KB |
Output is correct |
34 |
Correct |
38 ms |
3420 KB |
Output is correct |
35 |
Correct |
29 ms |
3524 KB |
Output is correct |
36 |
Correct |
30 ms |
3288 KB |
Output is correct |
37 |
Correct |
29 ms |
3420 KB |
Output is correct |
38 |
Correct |
31 ms |
3400 KB |
Output is correct |
39 |
Correct |
30 ms |
3472 KB |
Output is correct |
40 |
Correct |
29 ms |
3392 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
536 KB |
Output is correct |
47 |
Correct |
7 ms |
856 KB |
Output is correct |
48 |
Correct |
7 ms |
860 KB |
Output is correct |
49 |
Correct |
12 ms |
1628 KB |
Output is correct |
50 |
Correct |
24 ms |
2652 KB |
Output is correct |
51 |
Correct |
36 ms |
3928 KB |
Output is correct |
52 |
Correct |
37 ms |
3924 KB |
Output is correct |
53 |
Correct |
35 ms |
3924 KB |
Output is correct |
54 |
Correct |
35 ms |
3712 KB |
Output is correct |
55 |
Correct |
35 ms |
3924 KB |
Output is correct |
56 |
Correct |
35 ms |
3924 KB |
Output is correct |
57 |
Correct |
35 ms |
3880 KB |
Output is correct |
58 |
Correct |
35 ms |
3932 KB |
Output is correct |
59 |
Correct |
35 ms |
3920 KB |
Output is correct |
60 |
Correct |
36 ms |
3836 KB |
Output is correct |
61 |
Correct |
35 ms |
3920 KB |
Output is correct |
62 |
Correct |
41 ms |
3924 KB |
Output is correct |
63 |
Correct |
35 ms |
3920 KB |
Output is correct |
64 |
Correct |
37 ms |
3920 KB |
Output is correct |
65 |
Correct |
36 ms |
3920 KB |
Output is correct |
66 |
Correct |
38 ms |
3924 KB |
Output is correct |
67 |
Correct |
35 ms |
3932 KB |
Output is correct |
68 |
Correct |
36 ms |
3920 KB |
Output is correct |
69 |
Correct |
35 ms |
3920 KB |
Output is correct |
70 |
Correct |
38 ms |
3936 KB |
Output is correct |
71 |
Correct |
8 ms |
1112 KB |
Output is correct |
72 |
Correct |
8 ms |
1116 KB |
Output is correct |
73 |
Correct |
8 ms |
968 KB |
Output is correct |
74 |
Correct |
8 ms |
1116 KB |
Output is correct |
75 |
Correct |
8 ms |
1116 KB |
Output is correct |
76 |
Correct |
18 ms |
1628 KB |
Output is correct |
77 |
Correct |
18 ms |
1852 KB |
Output is correct |
78 |
Correct |
22 ms |
1624 KB |
Output is correct |
79 |
Correct |
19 ms |
1624 KB |
Output is correct |
80 |
Correct |
19 ms |
1636 KB |
Output is correct |
81 |
Correct |
47 ms |
3160 KB |
Output is correct |
82 |
Correct |
45 ms |
3152 KB |
Output is correct |
83 |
Correct |
45 ms |
3164 KB |
Output is correct |
84 |
Correct |
45 ms |
3160 KB |
Output is correct |
85 |
Correct |
42 ms |
3160 KB |
Output is correct |
86 |
Correct |
100 ms |
3672 KB |
Output is correct |
87 |
Correct |
100 ms |
3544 KB |
Output is correct |
88 |
Correct |
100 ms |
3528 KB |
Output is correct |
89 |
Correct |
105 ms |
3536 KB |
Output is correct |
90 |
Correct |
102 ms |
3544 KB |
Output is correct |
91 |
Correct |
1851 ms |
6852 KB |
Output is correct |
92 |
Correct |
1751 ms |
6856 KB |
Output is correct |
93 |
Correct |
1784 ms |
6852 KB |
Output is correct |
94 |
Correct |
1770 ms |
6864 KB |
Output is correct |
95 |
Correct |
1615 ms |
6852 KB |
Output is correct |
96 |
Correct |
6997 ms |
9408 KB |
Output is correct |
97 |
Correct |
6792 ms |
9408 KB |
Output is correct |
98 |
Execution timed out |
7067 ms |
9412 KB |
Time limit exceeded |
99 |
Halted |
0 ms |
0 KB |
- |