Submission #964859

# Submission time Handle Problem Language Result Execution time Memory
964859 2024-04-17T16:41:49 Z MinaRagy06 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 17372 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, q;
	cin >> n >> q;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		map<int, int> frq;
		for (int i = l; i <= r; i++) {
			frq[a[i]]++;
		}
		vector<int> t;
		for (auto [x, cnt] : frq) {
			t.push_back(cnt);
		}
		sort(t.rbegin(), t.rend());
		deque<int> v;
		int cur = 0;
		for (auto j : t) {
			if (cur & 1) {
				v.push_back(j);
			} else {
				v.push_front(j);
			}
			cur ^= 1;
		}
		n = v.size();
		ll ans = 0;
		ll sum = 0, sum2 = 0;
		for (int i = n - 1; i >= 0; i--) {
			ans += 1ll * v[i] * (v[i] + 1) / 2;
			ans += 1ll * v[i] * sum2;
			ans -= 1ll * v[i] * (i - 1) * sum;
			sum += v[i];
			sum2 += v[i] * i;
// 			for (int j = i + 1; j < n; j++) {
// 				ans += 1ll * v[i] * v[j] * j - v[i] * (i - 1) * v[j];
// 			}
		}
		cout << ans << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 600 KB Output is correct
5 Correct 13 ms 1280 KB Output is correct
6 Correct 19 ms 1628 KB Output is correct
7 Correct 15 ms 1628 KB Output is correct
8 Correct 22 ms 1628 KB Output is correct
9 Correct 18 ms 1628 KB Output is correct
10 Correct 17 ms 1624 KB Output is correct
11 Correct 17 ms 1628 KB Output is correct
12 Correct 19 ms 1624 KB Output is correct
13 Correct 17 ms 1372 KB Output is correct
14 Correct 17 ms 1372 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 600 KB Output is correct
5 Correct 13 ms 1280 KB Output is correct
6 Correct 19 ms 1628 KB Output is correct
7 Correct 15 ms 1628 KB Output is correct
8 Correct 22 ms 1628 KB Output is correct
9 Correct 18 ms 1628 KB Output is correct
10 Correct 17 ms 1624 KB Output is correct
11 Correct 17 ms 1628 KB Output is correct
12 Correct 19 ms 1624 KB Output is correct
13 Correct 17 ms 1372 KB Output is correct
14 Correct 17 ms 1372 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
16 Correct 1 ms 516 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 6 ms 604 KB Output is correct
20 Correct 16 ms 1232 KB Output is correct
21 Correct 19 ms 1624 KB Output is correct
22 Correct 21 ms 1624 KB Output is correct
23 Correct 19 ms 1628 KB Output is correct
24 Correct 21 ms 1628 KB Output is correct
25 Correct 27 ms 1620 KB Output is correct
26 Correct 20 ms 1624 KB Output is correct
27 Correct 19 ms 1624 KB Output is correct
28 Correct 19 ms 1628 KB Output is correct
29 Correct 23 ms 1372 KB Output is correct
30 Correct 21 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 600 KB Output is correct
5 Correct 13 ms 1280 KB Output is correct
6 Correct 19 ms 1628 KB Output is correct
7 Correct 15 ms 1628 KB Output is correct
8 Correct 22 ms 1628 KB Output is correct
9 Correct 18 ms 1628 KB Output is correct
10 Correct 17 ms 1624 KB Output is correct
11 Correct 17 ms 1628 KB Output is correct
12 Correct 19 ms 1624 KB Output is correct
13 Correct 17 ms 1372 KB Output is correct
14 Correct 17 ms 1372 KB Output is correct
15 Correct 17 ms 1628 KB Output is correct
16 Correct 1 ms 516 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 6 ms 604 KB Output is correct
20 Correct 16 ms 1232 KB Output is correct
21 Correct 19 ms 1624 KB Output is correct
22 Correct 21 ms 1624 KB Output is correct
23 Correct 19 ms 1628 KB Output is correct
24 Correct 21 ms 1628 KB Output is correct
25 Correct 27 ms 1620 KB Output is correct
26 Correct 20 ms 1624 KB Output is correct
27 Correct 19 ms 1624 KB Output is correct
28 Correct 19 ms 1628 KB Output is correct
29 Correct 23 ms 1372 KB Output is correct
30 Correct 21 ms 1368 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 6 ms 604 KB Output is correct
38 Correct 5 ms 688 KB Output is correct
39 Correct 11 ms 840 KB Output is correct
40 Correct 21 ms 1112 KB Output is correct
41 Correct 31 ms 1620 KB Output is correct
42 Correct 29 ms 1676 KB Output is correct
43 Correct 32 ms 1628 KB Output is correct
44 Correct 30 ms 1628 KB Output is correct
45 Correct 30 ms 1640 KB Output is correct
46 Correct 31 ms 1628 KB Output is correct
47 Correct 33 ms 1628 KB Output is correct
48 Correct 36 ms 1676 KB Output is correct
49 Correct 30 ms 1624 KB Output is correct
50 Correct 29 ms 1624 KB Output is correct
51 Correct 34 ms 1624 KB Output is correct
52 Correct 41 ms 1628 KB Output is correct
53 Correct 30 ms 1628 KB Output is correct
54 Correct 33 ms 1636 KB Output is correct
55 Correct 40 ms 1616 KB Output is correct
56 Correct 30 ms 1628 KB Output is correct
57 Correct 30 ms 1628 KB Output is correct
58 Correct 30 ms 1624 KB Output is correct
59 Correct 32 ms 1628 KB Output is correct
60 Correct 30 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 13 ms 1280 KB Output is correct
16 Correct 19 ms 1628 KB Output is correct
17 Correct 15 ms 1628 KB Output is correct
18 Correct 22 ms 1628 KB Output is correct
19 Correct 18 ms 1628 KB Output is correct
20 Correct 17 ms 1624 KB Output is correct
21 Correct 17 ms 1628 KB Output is correct
22 Correct 19 ms 1624 KB Output is correct
23 Correct 17 ms 1372 KB Output is correct
24 Correct 17 ms 1372 KB Output is correct
25 Correct 17 ms 1628 KB Output is correct
26 Correct 1 ms 516 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 6 ms 604 KB Output is correct
30 Correct 16 ms 1232 KB Output is correct
31 Correct 19 ms 1624 KB Output is correct
32 Correct 21 ms 1624 KB Output is correct
33 Correct 19 ms 1628 KB Output is correct
34 Correct 21 ms 1628 KB Output is correct
35 Correct 27 ms 1620 KB Output is correct
36 Correct 20 ms 1624 KB Output is correct
37 Correct 19 ms 1624 KB Output is correct
38 Correct 19 ms 1628 KB Output is correct
39 Correct 23 ms 1372 KB Output is correct
40 Correct 21 ms 1368 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 5 ms 688 KB Output is correct
49 Correct 11 ms 840 KB Output is correct
50 Correct 21 ms 1112 KB Output is correct
51 Correct 31 ms 1620 KB Output is correct
52 Correct 29 ms 1676 KB Output is correct
53 Correct 32 ms 1628 KB Output is correct
54 Correct 30 ms 1628 KB Output is correct
55 Correct 30 ms 1640 KB Output is correct
56 Correct 31 ms 1628 KB Output is correct
57 Correct 33 ms 1628 KB Output is correct
58 Correct 36 ms 1676 KB Output is correct
59 Correct 30 ms 1624 KB Output is correct
60 Correct 29 ms 1624 KB Output is correct
61 Correct 34 ms 1624 KB Output is correct
62 Correct 41 ms 1628 KB Output is correct
63 Correct 30 ms 1628 KB Output is correct
64 Correct 33 ms 1636 KB Output is correct
65 Correct 40 ms 1616 KB Output is correct
66 Correct 30 ms 1628 KB Output is correct
67 Correct 30 ms 1628 KB Output is correct
68 Correct 30 ms 1624 KB Output is correct
69 Correct 32 ms 1628 KB Output is correct
70 Correct 30 ms 1620 KB Output is correct
71 Correct 7 ms 744 KB Output is correct
72 Correct 6 ms 604 KB Output is correct
73 Correct 6 ms 600 KB Output is correct
74 Correct 6 ms 600 KB Output is correct
75 Correct 6 ms 600 KB Output is correct
76 Correct 14 ms 1116 KB Output is correct
77 Correct 13 ms 1116 KB Output is correct
78 Correct 14 ms 1104 KB Output is correct
79 Correct 14 ms 1112 KB Output is correct
80 Correct 14 ms 1116 KB Output is correct
81 Correct 30 ms 1628 KB Output is correct
82 Correct 29 ms 1660 KB Output is correct
83 Correct 30 ms 1628 KB Output is correct
84 Correct 29 ms 1644 KB Output is correct
85 Correct 29 ms 1628 KB Output is correct
86 Correct 36 ms 2128 KB Output is correct
87 Correct 38 ms 2256 KB Output is correct
88 Correct 36 ms 2252 KB Output is correct
89 Correct 36 ms 2252 KB Output is correct
90 Correct 36 ms 2248 KB Output is correct
91 Correct 85 ms 7112 KB Output is correct
92 Correct 78 ms 8648 KB Output is correct
93 Correct 78 ms 8656 KB Output is correct
94 Correct 83 ms 8908 KB Output is correct
95 Correct 91 ms 8732 KB Output is correct
96 Correct 106 ms 14644 KB Output is correct
97 Correct 106 ms 14396 KB Output is correct
98 Correct 124 ms 14496 KB Output is correct
99 Correct 110 ms 14280 KB Output is correct
100 Correct 109 ms 14280 KB Output is correct
101 Correct 110 ms 14280 KB Output is correct
102 Correct 118 ms 14284 KB Output is correct
103 Correct 106 ms 14260 KB Output is correct
104 Correct 114 ms 14284 KB Output is correct
105 Correct 105 ms 14284 KB Output is correct
106 Correct 123 ms 17188 KB Output is correct
107 Correct 154 ms 17104 KB Output is correct
108 Correct 124 ms 17232 KB Output is correct
109 Correct 118 ms 17216 KB Output is correct
110 Correct 122 ms 17188 KB Output is correct
111 Correct 118 ms 17216 KB Output is correct
112 Correct 136 ms 17196 KB Output is correct
113 Correct 137 ms 17372 KB Output is correct
114 Correct 118 ms 17100 KB Output is correct
115 Correct 129 ms 17152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 13 ms 1280 KB Output is correct
16 Correct 19 ms 1628 KB Output is correct
17 Correct 15 ms 1628 KB Output is correct
18 Correct 22 ms 1628 KB Output is correct
19 Correct 18 ms 1628 KB Output is correct
20 Correct 17 ms 1624 KB Output is correct
21 Correct 17 ms 1628 KB Output is correct
22 Correct 19 ms 1624 KB Output is correct
23 Correct 17 ms 1372 KB Output is correct
24 Correct 17 ms 1372 KB Output is correct
25 Correct 17 ms 1628 KB Output is correct
26 Correct 1 ms 516 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 6 ms 604 KB Output is correct
30 Correct 16 ms 1232 KB Output is correct
31 Correct 19 ms 1624 KB Output is correct
32 Correct 21 ms 1624 KB Output is correct
33 Correct 19 ms 1628 KB Output is correct
34 Correct 21 ms 1628 KB Output is correct
35 Correct 27 ms 1620 KB Output is correct
36 Correct 20 ms 1624 KB Output is correct
37 Correct 19 ms 1624 KB Output is correct
38 Correct 19 ms 1628 KB Output is correct
39 Correct 23 ms 1372 KB Output is correct
40 Correct 21 ms 1368 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 6 ms 604 KB Output is correct
48 Correct 5 ms 688 KB Output is correct
49 Correct 11 ms 840 KB Output is correct
50 Correct 21 ms 1112 KB Output is correct
51 Correct 31 ms 1620 KB Output is correct
52 Correct 29 ms 1676 KB Output is correct
53 Correct 32 ms 1628 KB Output is correct
54 Correct 30 ms 1628 KB Output is correct
55 Correct 30 ms 1640 KB Output is correct
56 Correct 31 ms 1628 KB Output is correct
57 Correct 33 ms 1628 KB Output is correct
58 Correct 36 ms 1676 KB Output is correct
59 Correct 30 ms 1624 KB Output is correct
60 Correct 29 ms 1624 KB Output is correct
61 Correct 34 ms 1624 KB Output is correct
62 Correct 41 ms 1628 KB Output is correct
63 Correct 30 ms 1628 KB Output is correct
64 Correct 33 ms 1636 KB Output is correct
65 Correct 40 ms 1616 KB Output is correct
66 Correct 30 ms 1628 KB Output is correct
67 Correct 30 ms 1628 KB Output is correct
68 Correct 30 ms 1624 KB Output is correct
69 Correct 32 ms 1628 KB Output is correct
70 Correct 30 ms 1620 KB Output is correct
71 Correct 7 ms 744 KB Output is correct
72 Correct 6 ms 604 KB Output is correct
73 Correct 6 ms 600 KB Output is correct
74 Correct 6 ms 600 KB Output is correct
75 Correct 6 ms 600 KB Output is correct
76 Correct 14 ms 1116 KB Output is correct
77 Correct 13 ms 1116 KB Output is correct
78 Correct 14 ms 1104 KB Output is correct
79 Correct 14 ms 1112 KB Output is correct
80 Correct 14 ms 1116 KB Output is correct
81 Correct 30 ms 1628 KB Output is correct
82 Correct 29 ms 1660 KB Output is correct
83 Correct 30 ms 1628 KB Output is correct
84 Correct 29 ms 1644 KB Output is correct
85 Correct 29 ms 1628 KB Output is correct
86 Correct 36 ms 2128 KB Output is correct
87 Correct 38 ms 2256 KB Output is correct
88 Correct 36 ms 2252 KB Output is correct
89 Correct 36 ms 2252 KB Output is correct
90 Correct 36 ms 2248 KB Output is correct
91 Correct 85 ms 7112 KB Output is correct
92 Correct 78 ms 8648 KB Output is correct
93 Correct 78 ms 8656 KB Output is correct
94 Correct 83 ms 8908 KB Output is correct
95 Correct 91 ms 8732 KB Output is correct
96 Correct 106 ms 14644 KB Output is correct
97 Correct 106 ms 14396 KB Output is correct
98 Correct 124 ms 14496 KB Output is correct
99 Correct 110 ms 14280 KB Output is correct
100 Correct 109 ms 14280 KB Output is correct
101 Correct 110 ms 14280 KB Output is correct
102 Correct 118 ms 14284 KB Output is correct
103 Correct 106 ms 14260 KB Output is correct
104 Correct 114 ms 14284 KB Output is correct
105 Correct 105 ms 14284 KB Output is correct
106 Correct 123 ms 17188 KB Output is correct
107 Correct 154 ms 17104 KB Output is correct
108 Correct 124 ms 17232 KB Output is correct
109 Correct 118 ms 17216 KB Output is correct
110 Correct 122 ms 17188 KB Output is correct
111 Correct 118 ms 17216 KB Output is correct
112 Correct 136 ms 17196 KB Output is correct
113 Correct 137 ms 17372 KB Output is correct
114 Correct 118 ms 17100 KB Output is correct
115 Correct 129 ms 17152 KB Output is correct
116 Correct 4486 ms 1440 KB Output is correct
117 Correct 5657 ms 1264 KB Output is correct
118 Execution timed out 7061 ms 1024 KB Time limit exceeded
119 Halted 0 ms 0 KB -