Submission #881898

# Submission time Handle Problem Language Result Execution time Memory
881898 2023-12-02T08:19:00 Z TAhmed33 Diversity (CEOI21_diversity) C++
64 / 100
7000 ms 5908 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target ("popcnt")
typedef long long ll;
const int MAXN = 3e5 + 25;
const int ORIGIN = 300000;
int n, a[MAXN], q, n1;
int freq[MAXN], freq2[MAXN];
inline ll sq (ll x) {
	return ((x * (x + 1)) >> 1ll);
}
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--) {
		memset(freq, 0, sizeof(freq));
		memset(freq2, 0, sizeof(freq2));
		int l, r;
		cin >> l >> r;
		ll o = r - l + 1;
		n1 = 0;
		for (int i = l; i <= r; i++) {
			if (freq[a[i]]) freq2[freq[a[i]]]--;
			else n1++;
			freq2[++freq[a[i]]]++;
		}
		int c = 0;
		ll ans = 0;
		ll p = 0, q = 0;
		for (int i = 1; i <= ORIGIN; i++) {
			ll j = freq2[i];
			for (int l = 1; l <= j; l++) {
				c ^= 1;
				if (c) {
					ans += sq(p) + sq(o - p - i); p += i;
				} else {
					ans += sq(q) + sq(o - q - i); q += i;
				}
			}
		}
		cout << n1 * sq(o) - ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 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 1 ms 2652 KB Output is correct
4 Correct 5 ms 3164 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 14 ms 4444 KB Output is correct
7 Correct 13 ms 4344 KB Output is correct
8 Correct 13 ms 4440 KB Output is correct
9 Correct 14 ms 4444 KB Output is correct
10 Correct 15 ms 4492 KB Output is correct
11 Correct 14 ms 4700 KB Output is correct
12 Correct 14 ms 4444 KB Output is correct
13 Correct 13 ms 4472 KB Output is correct
14 Correct 14 ms 4444 KB Output is correct
15 Correct 14 ms 4444 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 1 ms 2652 KB Output is correct
4 Correct 5 ms 3164 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 14 ms 4444 KB Output is correct
7 Correct 13 ms 4344 KB Output is correct
8 Correct 13 ms 4440 KB Output is correct
9 Correct 14 ms 4444 KB Output is correct
10 Correct 15 ms 4492 KB Output is correct
11 Correct 14 ms 4700 KB Output is correct
12 Correct 14 ms 4444 KB Output is correct
13 Correct 13 ms 4472 KB Output is correct
14 Correct 14 ms 4444 KB Output is correct
15 Correct 14 ms 4444 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2768 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 5 ms 3420 KB Output is correct
20 Correct 10 ms 4056 KB Output is correct
21 Correct 15 ms 4684 KB Output is correct
22 Correct 15 ms 4700 KB Output is correct
23 Correct 15 ms 4700 KB Output is correct
24 Correct 18 ms 4700 KB Output is correct
25 Correct 15 ms 4700 KB Output is correct
26 Correct 15 ms 4700 KB Output is correct
27 Correct 15 ms 4564 KB Output is correct
28 Correct 15 ms 4952 KB Output is correct
29 Correct 16 ms 4704 KB Output is correct
30 Correct 14 ms 4532 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 1 ms 2652 KB Output is correct
4 Correct 5 ms 3164 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 14 ms 4444 KB Output is correct
7 Correct 13 ms 4344 KB Output is correct
8 Correct 13 ms 4440 KB Output is correct
9 Correct 14 ms 4444 KB Output is correct
10 Correct 15 ms 4492 KB Output is correct
11 Correct 14 ms 4700 KB Output is correct
12 Correct 14 ms 4444 KB Output is correct
13 Correct 13 ms 4472 KB Output is correct
14 Correct 14 ms 4444 KB Output is correct
15 Correct 14 ms 4444 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2768 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 5 ms 3420 KB Output is correct
20 Correct 10 ms 4056 KB Output is correct
21 Correct 15 ms 4684 KB Output is correct
22 Correct 15 ms 4700 KB Output is correct
23 Correct 15 ms 4700 KB Output is correct
24 Correct 18 ms 4700 KB Output is correct
25 Correct 15 ms 4700 KB Output is correct
26 Correct 15 ms 4700 KB Output is correct
27 Correct 15 ms 4564 KB Output is correct
28 Correct 15 ms 4952 KB Output is correct
29 Correct 16 ms 4704 KB Output is correct
30 Correct 14 ms 4532 KB Output is correct
31 Correct 1 ms 2764 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2648 KB Output is correct
36 Correct 2 ms 2648 KB Output is correct
37 Correct 3 ms 3028 KB Output is correct
38 Correct 3 ms 3160 KB Output is correct
39 Correct 6 ms 3420 KB Output is correct
40 Correct 11 ms 4188 KB Output is correct
41 Correct 16 ms 4956 KB Output is correct
42 Correct 16 ms 5104 KB Output is correct
43 Correct 16 ms 4944 KB Output is correct
44 Correct 16 ms 4956 KB Output is correct
45 Correct 16 ms 4956 KB Output is correct
46 Correct 16 ms 4928 KB Output is correct
47 Correct 15 ms 4952 KB Output is correct
48 Correct 16 ms 4956 KB Output is correct
49 Correct 16 ms 4852 KB Output is correct
50 Correct 16 ms 4956 KB Output is correct
51 Correct 20 ms 5036 KB Output is correct
52 Correct 20 ms 4948 KB Output is correct
53 Correct 16 ms 4952 KB Output is correct
54 Correct 15 ms 4952 KB Output is correct
55 Correct 16 ms 4944 KB Output is correct
56 Correct 16 ms 4952 KB Output is correct
57 Correct 15 ms 4956 KB Output is correct
58 Correct 16 ms 4884 KB Output is correct
59 Correct 17 ms 5144 KB Output is correct
60 Correct 18 ms 5080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 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 1 ms 2652 KB Output is correct
14 Correct 5 ms 3164 KB Output is correct
15 Correct 9 ms 3932 KB Output is correct
16 Correct 14 ms 4444 KB Output is correct
17 Correct 13 ms 4344 KB Output is correct
18 Correct 13 ms 4440 KB Output is correct
19 Correct 14 ms 4444 KB Output is correct
20 Correct 15 ms 4492 KB Output is correct
21 Correct 14 ms 4700 KB Output is correct
22 Correct 14 ms 4444 KB Output is correct
23 Correct 13 ms 4472 KB Output is correct
24 Correct 14 ms 4444 KB Output is correct
25 Correct 14 ms 4444 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2768 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 5 ms 3420 KB Output is correct
30 Correct 10 ms 4056 KB Output is correct
31 Correct 15 ms 4684 KB Output is correct
32 Correct 15 ms 4700 KB Output is correct
33 Correct 15 ms 4700 KB Output is correct
34 Correct 18 ms 4700 KB Output is correct
35 Correct 15 ms 4700 KB Output is correct
36 Correct 15 ms 4700 KB Output is correct
37 Correct 15 ms 4564 KB Output is correct
38 Correct 15 ms 4952 KB Output is correct
39 Correct 16 ms 4704 KB Output is correct
40 Correct 14 ms 4532 KB Output is correct
41 Correct 1 ms 2764 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2648 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 3 ms 3028 KB Output is correct
48 Correct 3 ms 3160 KB Output is correct
49 Correct 6 ms 3420 KB Output is correct
50 Correct 11 ms 4188 KB Output is correct
51 Correct 16 ms 4956 KB Output is correct
52 Correct 16 ms 5104 KB Output is correct
53 Correct 16 ms 4944 KB Output is correct
54 Correct 16 ms 4956 KB Output is correct
55 Correct 16 ms 4956 KB Output is correct
56 Correct 16 ms 4928 KB Output is correct
57 Correct 15 ms 4952 KB Output is correct
58 Correct 16 ms 4956 KB Output is correct
59 Correct 16 ms 4852 KB Output is correct
60 Correct 16 ms 4956 KB Output is correct
61 Correct 20 ms 5036 KB Output is correct
62 Correct 20 ms 4948 KB Output is correct
63 Correct 16 ms 4952 KB Output is correct
64 Correct 15 ms 4952 KB Output is correct
65 Correct 16 ms 4944 KB Output is correct
66 Correct 16 ms 4952 KB Output is correct
67 Correct 15 ms 4956 KB Output is correct
68 Correct 16 ms 4884 KB Output is correct
69 Correct 17 ms 5144 KB Output is correct
70 Correct 18 ms 5080 KB Output is correct
71 Correct 4 ms 3164 KB Output is correct
72 Correct 4 ms 3164 KB Output is correct
73 Correct 4 ms 3164 KB Output is correct
74 Correct 5 ms 3164 KB Output is correct
75 Correct 4 ms 3032 KB Output is correct
76 Correct 8 ms 3676 KB Output is correct
77 Correct 7 ms 3628 KB Output is correct
78 Correct 6 ms 3420 KB Output is correct
79 Correct 6 ms 3676 KB Output is correct
80 Correct 6 ms 3676 KB Output is correct
81 Correct 13 ms 4440 KB Output is correct
82 Correct 12 ms 4696 KB Output is correct
83 Correct 14 ms 4412 KB Output is correct
84 Correct 12 ms 4444 KB Output is correct
85 Correct 12 ms 4440 KB Output is correct
86 Correct 14 ms 4444 KB Output is correct
87 Correct 13 ms 4436 KB Output is correct
88 Correct 14 ms 4444 KB Output is correct
89 Correct 13 ms 4440 KB Output is correct
90 Correct 13 ms 4444 KB Output is correct
91 Correct 20 ms 5596 KB Output is correct
92 Correct 19 ms 5456 KB Output is correct
93 Correct 20 ms 5460 KB Output is correct
94 Correct 19 ms 5468 KB Output is correct
95 Correct 19 ms 5468 KB Output is correct
96 Correct 22 ms 5696 KB Output is correct
97 Correct 22 ms 5648 KB Output is correct
98 Correct 23 ms 5580 KB Output is correct
99 Correct 22 ms 5740 KB Output is correct
100 Correct 22 ms 5716 KB Output is correct
101 Correct 23 ms 5724 KB Output is correct
102 Correct 22 ms 5712 KB Output is correct
103 Correct 25 ms 5688 KB Output is correct
104 Correct 22 ms 5772 KB Output is correct
105 Correct 22 ms 5724 KB Output is correct
106 Correct 22 ms 5724 KB Output is correct
107 Correct 21 ms 5720 KB Output is correct
108 Correct 22 ms 5724 KB Output is correct
109 Correct 22 ms 5716 KB Output is correct
110 Correct 24 ms 5908 KB Output is correct
111 Correct 22 ms 5724 KB Output is correct
112 Correct 24 ms 5724 KB Output is correct
113 Correct 22 ms 5576 KB Output is correct
114 Correct 22 ms 5724 KB Output is correct
115 Correct 22 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 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 1 ms 2652 KB Output is correct
14 Correct 5 ms 3164 KB Output is correct
15 Correct 9 ms 3932 KB Output is correct
16 Correct 14 ms 4444 KB Output is correct
17 Correct 13 ms 4344 KB Output is correct
18 Correct 13 ms 4440 KB Output is correct
19 Correct 14 ms 4444 KB Output is correct
20 Correct 15 ms 4492 KB Output is correct
21 Correct 14 ms 4700 KB Output is correct
22 Correct 14 ms 4444 KB Output is correct
23 Correct 13 ms 4472 KB Output is correct
24 Correct 14 ms 4444 KB Output is correct
25 Correct 14 ms 4444 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2768 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 5 ms 3420 KB Output is correct
30 Correct 10 ms 4056 KB Output is correct
31 Correct 15 ms 4684 KB Output is correct
32 Correct 15 ms 4700 KB Output is correct
33 Correct 15 ms 4700 KB Output is correct
34 Correct 18 ms 4700 KB Output is correct
35 Correct 15 ms 4700 KB Output is correct
36 Correct 15 ms 4700 KB Output is correct
37 Correct 15 ms 4564 KB Output is correct
38 Correct 15 ms 4952 KB Output is correct
39 Correct 16 ms 4704 KB Output is correct
40 Correct 14 ms 4532 KB Output is correct
41 Correct 1 ms 2764 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2648 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 3 ms 3028 KB Output is correct
48 Correct 3 ms 3160 KB Output is correct
49 Correct 6 ms 3420 KB Output is correct
50 Correct 11 ms 4188 KB Output is correct
51 Correct 16 ms 4956 KB Output is correct
52 Correct 16 ms 5104 KB Output is correct
53 Correct 16 ms 4944 KB Output is correct
54 Correct 16 ms 4956 KB Output is correct
55 Correct 16 ms 4956 KB Output is correct
56 Correct 16 ms 4928 KB Output is correct
57 Correct 15 ms 4952 KB Output is correct
58 Correct 16 ms 4956 KB Output is correct
59 Correct 16 ms 4852 KB Output is correct
60 Correct 16 ms 4956 KB Output is correct
61 Correct 20 ms 5036 KB Output is correct
62 Correct 20 ms 4948 KB Output is correct
63 Correct 16 ms 4952 KB Output is correct
64 Correct 15 ms 4952 KB Output is correct
65 Correct 16 ms 4944 KB Output is correct
66 Correct 16 ms 4952 KB Output is correct
67 Correct 15 ms 4956 KB Output is correct
68 Correct 16 ms 4884 KB Output is correct
69 Correct 17 ms 5144 KB Output is correct
70 Correct 18 ms 5080 KB Output is correct
71 Correct 4 ms 3164 KB Output is correct
72 Correct 4 ms 3164 KB Output is correct
73 Correct 4 ms 3164 KB Output is correct
74 Correct 5 ms 3164 KB Output is correct
75 Correct 4 ms 3032 KB Output is correct
76 Correct 8 ms 3676 KB Output is correct
77 Correct 7 ms 3628 KB Output is correct
78 Correct 6 ms 3420 KB Output is correct
79 Correct 6 ms 3676 KB Output is correct
80 Correct 6 ms 3676 KB Output is correct
81 Correct 13 ms 4440 KB Output is correct
82 Correct 12 ms 4696 KB Output is correct
83 Correct 14 ms 4412 KB Output is correct
84 Correct 12 ms 4444 KB Output is correct
85 Correct 12 ms 4440 KB Output is correct
86 Correct 14 ms 4444 KB Output is correct
87 Correct 13 ms 4436 KB Output is correct
88 Correct 14 ms 4444 KB Output is correct
89 Correct 13 ms 4440 KB Output is correct
90 Correct 13 ms 4444 KB Output is correct
91 Correct 20 ms 5596 KB Output is correct
92 Correct 19 ms 5456 KB Output is correct
93 Correct 20 ms 5460 KB Output is correct
94 Correct 19 ms 5468 KB Output is correct
95 Correct 19 ms 5468 KB Output is correct
96 Correct 22 ms 5696 KB Output is correct
97 Correct 22 ms 5648 KB Output is correct
98 Correct 23 ms 5580 KB Output is correct
99 Correct 22 ms 5740 KB Output is correct
100 Correct 22 ms 5716 KB Output is correct
101 Correct 23 ms 5724 KB Output is correct
102 Correct 22 ms 5712 KB Output is correct
103 Correct 25 ms 5688 KB Output is correct
104 Correct 22 ms 5772 KB Output is correct
105 Correct 22 ms 5724 KB Output is correct
106 Correct 22 ms 5724 KB Output is correct
107 Correct 21 ms 5720 KB Output is correct
108 Correct 22 ms 5724 KB Output is correct
109 Correct 22 ms 5716 KB Output is correct
110 Correct 24 ms 5908 KB Output is correct
111 Correct 22 ms 5724 KB Output is correct
112 Correct 24 ms 5724 KB Output is correct
113 Correct 22 ms 5576 KB Output is correct
114 Correct 22 ms 5724 KB Output is correct
115 Correct 22 ms 5740 KB Output is correct
116 Execution timed out 7044 ms 3564 KB Time limit exceeded
117 Halted 0 ms 0 KB -