Submission #881893

# Submission time Handle Problem Language Result Execution time Memory
881893 2023-12-02T08:01:56 Z TAhmed33 Diversity (CEOI21_diversity) C++
64 / 100
7000 ms 6716 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 25;
int n, a[MAXN], q, n1;
int freq[MAXN];
int main () {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	while (q--) {
		memset(freq, 0, sizeof(freq));
		int l, r;
		cin >> l >> r;
		for (int i = l; i <= r; i++) freq[a[i]]++;
		vector <int> x;	
		for (int i = 1; i < MAXN; i++) {
			if (freq[i]) {
				x.push_back(freq[i]);
			}
		}
		n1 = x.size();
		sort(x.begin(), x.end());
		deque <int> y;
		for (int i = n1 - 1; i >= 0; i -= 2) y.push_front(x[i]);
		for (int i = n1 - 2; i >= 0; i -= 2) y.push_back(x[i]);
		ll o = r - l + 1;
		ll rr = 0, sum = 0;
		for (auto i : y) {
			sum += rr * (rr + 1) / 2 + (o - i - rr) * (o - i - rr + 1) / 2;
			rr += i;
		}
		sum = ll(o) * ll((o + 1)) / 2 * ((ll)y.size()) - sum;
		cout << sum << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2476 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 12 ms 2684 KB Output is correct
5 Correct 23 ms 2900 KB Output is correct
6 Correct 36 ms 3412 KB Output is correct
7 Correct 34 ms 3216 KB Output is correct
8 Correct 36 ms 3156 KB Output is correct
9 Correct 34 ms 3236 KB Output is correct
10 Correct 36 ms 3412 KB Output is correct
11 Correct 36 ms 3416 KB Output is correct
12 Correct 43 ms 3408 KB Output is correct
13 Correct 34 ms 3240 KB Output is correct
14 Correct 34 ms 3152 KB Output is correct
15 Correct 34 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 12 ms 2684 KB Output is correct
5 Correct 23 ms 2900 KB Output is correct
6 Correct 36 ms 3412 KB Output is correct
7 Correct 34 ms 3216 KB Output is correct
8 Correct 36 ms 3156 KB Output is correct
9 Correct 34 ms 3236 KB Output is correct
10 Correct 36 ms 3412 KB Output is correct
11 Correct 36 ms 3416 KB Output is correct
12 Correct 43 ms 3408 KB Output is correct
13 Correct 34 ms 3240 KB Output is correct
14 Correct 34 ms 3152 KB Output is correct
15 Correct 34 ms 3240 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 14 ms 2908 KB Output is correct
20 Correct 27 ms 3000 KB Output is correct
21 Correct 41 ms 3476 KB Output is correct
22 Correct 38 ms 3412 KB Output is correct
23 Correct 38 ms 3416 KB Output is correct
24 Correct 38 ms 3520 KB Output is correct
25 Correct 38 ms 3348 KB Output is correct
26 Correct 41 ms 3492 KB Output is correct
27 Correct 41 ms 3488 KB Output is correct
28 Correct 37 ms 3408 KB Output is correct
29 Correct 37 ms 3416 KB Output is correct
30 Correct 38 ms 3488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 12 ms 2684 KB Output is correct
5 Correct 23 ms 2900 KB Output is correct
6 Correct 36 ms 3412 KB Output is correct
7 Correct 34 ms 3216 KB Output is correct
8 Correct 36 ms 3156 KB Output is correct
9 Correct 34 ms 3236 KB Output is correct
10 Correct 36 ms 3412 KB Output is correct
11 Correct 36 ms 3416 KB Output is correct
12 Correct 43 ms 3408 KB Output is correct
13 Correct 34 ms 3240 KB Output is correct
14 Correct 34 ms 3152 KB Output is correct
15 Correct 34 ms 3240 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 14 ms 2908 KB Output is correct
20 Correct 27 ms 3000 KB Output is correct
21 Correct 41 ms 3476 KB Output is correct
22 Correct 38 ms 3412 KB Output is correct
23 Correct 38 ms 3416 KB Output is correct
24 Correct 38 ms 3520 KB Output is correct
25 Correct 38 ms 3348 KB Output is correct
26 Correct 41 ms 3492 KB Output is correct
27 Correct 41 ms 3488 KB Output is correct
28 Correct 37 ms 3408 KB Output is correct
29 Correct 37 ms 3416 KB Output is correct
30 Correct 38 ms 3488 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2504 KB Output is correct
37 Correct 10 ms 2668 KB Output is correct
38 Correct 10 ms 2652 KB Output is correct
39 Correct 16 ms 2856 KB Output is correct
40 Correct 31 ms 3408 KB Output is correct
41 Correct 46 ms 3668 KB Output is correct
42 Correct 47 ms 3872 KB Output is correct
43 Correct 45 ms 3668 KB Output is correct
44 Correct 46 ms 3772 KB Output is correct
45 Correct 48 ms 3880 KB Output is correct
46 Correct 46 ms 3924 KB Output is correct
47 Correct 47 ms 3872 KB Output is correct
48 Correct 46 ms 3752 KB Output is correct
49 Correct 46 ms 3664 KB Output is correct
50 Correct 47 ms 3932 KB Output is correct
51 Correct 45 ms 3932 KB Output is correct
52 Correct 50 ms 3924 KB Output is correct
53 Correct 47 ms 3876 KB Output is correct
54 Correct 46 ms 3880 KB Output is correct
55 Correct 57 ms 3864 KB Output is correct
56 Correct 49 ms 3732 KB Output is correct
57 Correct 45 ms 3668 KB Output is correct
58 Correct 46 ms 3856 KB Output is correct
59 Correct 47 ms 3924 KB Output is correct
60 Correct 46 ms 3880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2476 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 12 ms 2684 KB Output is correct
15 Correct 23 ms 2900 KB Output is correct
16 Correct 36 ms 3412 KB Output is correct
17 Correct 34 ms 3216 KB Output is correct
18 Correct 36 ms 3156 KB Output is correct
19 Correct 34 ms 3236 KB Output is correct
20 Correct 36 ms 3412 KB Output is correct
21 Correct 36 ms 3416 KB Output is correct
22 Correct 43 ms 3408 KB Output is correct
23 Correct 34 ms 3240 KB Output is correct
24 Correct 34 ms 3152 KB Output is correct
25 Correct 34 ms 3240 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 14 ms 2908 KB Output is correct
30 Correct 27 ms 3000 KB Output is correct
31 Correct 41 ms 3476 KB Output is correct
32 Correct 38 ms 3412 KB Output is correct
33 Correct 38 ms 3416 KB Output is correct
34 Correct 38 ms 3520 KB Output is correct
35 Correct 38 ms 3348 KB Output is correct
36 Correct 41 ms 3492 KB Output is correct
37 Correct 41 ms 3488 KB Output is correct
38 Correct 37 ms 3408 KB Output is correct
39 Correct 37 ms 3416 KB Output is correct
40 Correct 38 ms 3488 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2648 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2504 KB Output is correct
47 Correct 10 ms 2668 KB Output is correct
48 Correct 10 ms 2652 KB Output is correct
49 Correct 16 ms 2856 KB Output is correct
50 Correct 31 ms 3408 KB Output is correct
51 Correct 46 ms 3668 KB Output is correct
52 Correct 47 ms 3872 KB Output is correct
53 Correct 45 ms 3668 KB Output is correct
54 Correct 46 ms 3772 KB Output is correct
55 Correct 48 ms 3880 KB Output is correct
56 Correct 46 ms 3924 KB Output is correct
57 Correct 47 ms 3872 KB Output is correct
58 Correct 46 ms 3752 KB Output is correct
59 Correct 46 ms 3664 KB Output is correct
60 Correct 47 ms 3932 KB Output is correct
61 Correct 45 ms 3932 KB Output is correct
62 Correct 50 ms 3924 KB Output is correct
63 Correct 47 ms 3876 KB Output is correct
64 Correct 46 ms 3880 KB Output is correct
65 Correct 57 ms 3864 KB Output is correct
66 Correct 49 ms 3732 KB Output is correct
67 Correct 45 ms 3668 KB Output is correct
68 Correct 46 ms 3856 KB Output is correct
69 Correct 47 ms 3924 KB Output is correct
70 Correct 46 ms 3880 KB Output is correct
71 Correct 9 ms 2904 KB Output is correct
72 Correct 9 ms 2712 KB Output is correct
73 Correct 10 ms 2908 KB Output is correct
74 Correct 9 ms 2856 KB Output is correct
75 Correct 9 ms 2708 KB Output is correct
76 Correct 19 ms 3112 KB Output is correct
77 Correct 18 ms 3164 KB Output is correct
78 Correct 22 ms 3156 KB Output is correct
79 Correct 19 ms 3152 KB Output is correct
80 Correct 18 ms 3164 KB Output is correct
81 Correct 36 ms 3664 KB Output is correct
82 Correct 37 ms 3676 KB Output is correct
83 Correct 46 ms 3488 KB Output is correct
84 Correct 36 ms 3628 KB Output is correct
85 Correct 36 ms 3600 KB Output is correct
86 Correct 42 ms 3924 KB Output is correct
87 Correct 40 ms 3924 KB Output is correct
88 Correct 38 ms 3872 KB Output is correct
89 Correct 38 ms 3748 KB Output is correct
90 Correct 41 ms 3748 KB Output is correct
91 Correct 67 ms 5328 KB Output is correct
92 Correct 63 ms 5072 KB Output is correct
93 Correct 62 ms 5068 KB Output is correct
94 Correct 63 ms 5324 KB Output is correct
95 Correct 63 ms 5136 KB Output is correct
96 Correct 70 ms 6292 KB Output is correct
97 Correct 67 ms 6040 KB Output is correct
98 Correct 79 ms 6088 KB Output is correct
99 Correct 70 ms 6364 KB Output is correct
100 Correct 68 ms 6172 KB Output is correct
101 Correct 71 ms 6184 KB Output is correct
102 Correct 67 ms 6084 KB Output is correct
103 Correct 68 ms 6088 KB Output is correct
104 Correct 68 ms 6040 KB Output is correct
105 Correct 74 ms 6048 KB Output is correct
106 Correct 70 ms 6596 KB Output is correct
107 Correct 70 ms 6612 KB Output is correct
108 Correct 73 ms 6548 KB Output is correct
109 Correct 69 ms 6596 KB Output is correct
110 Correct 70 ms 6536 KB Output is correct
111 Correct 68 ms 6596 KB Output is correct
112 Correct 69 ms 6604 KB Output is correct
113 Correct 72 ms 6716 KB Output is correct
114 Correct 70 ms 6596 KB Output is correct
115 Correct 73 ms 6544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2476 KB Output is correct
3 Correct 1 ms 2492 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 12 ms 2684 KB Output is correct
15 Correct 23 ms 2900 KB Output is correct
16 Correct 36 ms 3412 KB Output is correct
17 Correct 34 ms 3216 KB Output is correct
18 Correct 36 ms 3156 KB Output is correct
19 Correct 34 ms 3236 KB Output is correct
20 Correct 36 ms 3412 KB Output is correct
21 Correct 36 ms 3416 KB Output is correct
22 Correct 43 ms 3408 KB Output is correct
23 Correct 34 ms 3240 KB Output is correct
24 Correct 34 ms 3152 KB Output is correct
25 Correct 34 ms 3240 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 14 ms 2908 KB Output is correct
30 Correct 27 ms 3000 KB Output is correct
31 Correct 41 ms 3476 KB Output is correct
32 Correct 38 ms 3412 KB Output is correct
33 Correct 38 ms 3416 KB Output is correct
34 Correct 38 ms 3520 KB Output is correct
35 Correct 38 ms 3348 KB Output is correct
36 Correct 41 ms 3492 KB Output is correct
37 Correct 41 ms 3488 KB Output is correct
38 Correct 37 ms 3408 KB Output is correct
39 Correct 37 ms 3416 KB Output is correct
40 Correct 38 ms 3488 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2648 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2504 KB Output is correct
47 Correct 10 ms 2668 KB Output is correct
48 Correct 10 ms 2652 KB Output is correct
49 Correct 16 ms 2856 KB Output is correct
50 Correct 31 ms 3408 KB Output is correct
51 Correct 46 ms 3668 KB Output is correct
52 Correct 47 ms 3872 KB Output is correct
53 Correct 45 ms 3668 KB Output is correct
54 Correct 46 ms 3772 KB Output is correct
55 Correct 48 ms 3880 KB Output is correct
56 Correct 46 ms 3924 KB Output is correct
57 Correct 47 ms 3872 KB Output is correct
58 Correct 46 ms 3752 KB Output is correct
59 Correct 46 ms 3664 KB Output is correct
60 Correct 47 ms 3932 KB Output is correct
61 Correct 45 ms 3932 KB Output is correct
62 Correct 50 ms 3924 KB Output is correct
63 Correct 47 ms 3876 KB Output is correct
64 Correct 46 ms 3880 KB Output is correct
65 Correct 57 ms 3864 KB Output is correct
66 Correct 49 ms 3732 KB Output is correct
67 Correct 45 ms 3668 KB Output is correct
68 Correct 46 ms 3856 KB Output is correct
69 Correct 47 ms 3924 KB Output is correct
70 Correct 46 ms 3880 KB Output is correct
71 Correct 9 ms 2904 KB Output is correct
72 Correct 9 ms 2712 KB Output is correct
73 Correct 10 ms 2908 KB Output is correct
74 Correct 9 ms 2856 KB Output is correct
75 Correct 9 ms 2708 KB Output is correct
76 Correct 19 ms 3112 KB Output is correct
77 Correct 18 ms 3164 KB Output is correct
78 Correct 22 ms 3156 KB Output is correct
79 Correct 19 ms 3152 KB Output is correct
80 Correct 18 ms 3164 KB Output is correct
81 Correct 36 ms 3664 KB Output is correct
82 Correct 37 ms 3676 KB Output is correct
83 Correct 46 ms 3488 KB Output is correct
84 Correct 36 ms 3628 KB Output is correct
85 Correct 36 ms 3600 KB Output is correct
86 Correct 42 ms 3924 KB Output is correct
87 Correct 40 ms 3924 KB Output is correct
88 Correct 38 ms 3872 KB Output is correct
89 Correct 38 ms 3748 KB Output is correct
90 Correct 41 ms 3748 KB Output is correct
91 Correct 67 ms 5328 KB Output is correct
92 Correct 63 ms 5072 KB Output is correct
93 Correct 62 ms 5068 KB Output is correct
94 Correct 63 ms 5324 KB Output is correct
95 Correct 63 ms 5136 KB Output is correct
96 Correct 70 ms 6292 KB Output is correct
97 Correct 67 ms 6040 KB Output is correct
98 Correct 79 ms 6088 KB Output is correct
99 Correct 70 ms 6364 KB Output is correct
100 Correct 68 ms 6172 KB Output is correct
101 Correct 71 ms 6184 KB Output is correct
102 Correct 67 ms 6084 KB Output is correct
103 Correct 68 ms 6088 KB Output is correct
104 Correct 68 ms 6040 KB Output is correct
105 Correct 74 ms 6048 KB Output is correct
106 Correct 70 ms 6596 KB Output is correct
107 Correct 70 ms 6612 KB Output is correct
108 Correct 73 ms 6548 KB Output is correct
109 Correct 69 ms 6596 KB Output is correct
110 Correct 70 ms 6536 KB Output is correct
111 Correct 68 ms 6596 KB Output is correct
112 Correct 69 ms 6604 KB Output is correct
113 Correct 72 ms 6716 KB Output is correct
114 Correct 70 ms 6596 KB Output is correct
115 Correct 73 ms 6544 KB Output is correct
116 Correct 6105 ms 3832 KB Output is correct
117 Correct 6273 ms 3780 KB Output is correct
118 Correct 6491 ms 3884 KB Output is correct
119 Execution timed out 7049 ms 4044 KB Time limit exceeded
120 Halted 0 ms 0 KB -