답안 #964855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964855 2024-04-17T16:34:08 Z MinaRagy06 Diversity (CEOI21_diversity) C++17
38 / 100
7000 ms 8852 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;
		for (int i = 0; i < n; i++) {
			ans += 1ll * v[i] * (v[i] + 1) / 2;
			for (int j = i + 1; j < n; j++) {
				ans += 1ll * v[i] * v[j] * (j - i + 1);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 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 348 KB Output is correct
# 결과 실행 시간 메모리 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 844 KB Output is correct
5 Correct 10 ms 1232 KB Output is correct
6 Correct 17 ms 2256 KB Output is correct
7 Correct 15 ms 2140 KB Output is correct
8 Correct 17 ms 2140 KB Output is correct
9 Correct 22 ms 2392 KB Output is correct
10 Correct 17 ms 2140 KB Output is correct
11 Correct 17 ms 2140 KB Output is correct
12 Correct 17 ms 2296 KB Output is correct
13 Correct 17 ms 2280 KB Output is correct
14 Correct 17 ms 2252 KB Output is correct
15 Correct 18 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 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 844 KB Output is correct
5 Correct 10 ms 1232 KB Output is correct
6 Correct 17 ms 2256 KB Output is correct
7 Correct 15 ms 2140 KB Output is correct
8 Correct 17 ms 2140 KB Output is correct
9 Correct 22 ms 2392 KB Output is correct
10 Correct 17 ms 2140 KB Output is correct
11 Correct 17 ms 2140 KB Output is correct
12 Correct 17 ms 2296 KB Output is correct
13 Correct 17 ms 2280 KB Output is correct
14 Correct 17 ms 2252 KB Output is correct
15 Correct 18 ms 2140 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1116 KB Output is correct
20 Correct 14 ms 1628 KB Output is correct
21 Correct 19 ms 2440 KB Output is correct
22 Correct 20 ms 2396 KB Output is correct
23 Correct 19 ms 2396 KB Output is correct
24 Correct 20 ms 2260 KB Output is correct
25 Correct 22 ms 2256 KB Output is correct
26 Correct 20 ms 2388 KB Output is correct
27 Correct 20 ms 2396 KB Output is correct
28 Correct 19 ms 2140 KB Output is correct
29 Correct 19 ms 2124 KB Output is correct
30 Correct 20 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 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 844 KB Output is correct
5 Correct 10 ms 1232 KB Output is correct
6 Correct 17 ms 2256 KB Output is correct
7 Correct 15 ms 2140 KB Output is correct
8 Correct 17 ms 2140 KB Output is correct
9 Correct 22 ms 2392 KB Output is correct
10 Correct 17 ms 2140 KB Output is correct
11 Correct 17 ms 2140 KB Output is correct
12 Correct 17 ms 2296 KB Output is correct
13 Correct 17 ms 2280 KB Output is correct
14 Correct 17 ms 2252 KB Output is correct
15 Correct 18 ms 2140 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1116 KB Output is correct
20 Correct 14 ms 1628 KB Output is correct
21 Correct 19 ms 2440 KB Output is correct
22 Correct 20 ms 2396 KB Output is correct
23 Correct 19 ms 2396 KB Output is correct
24 Correct 20 ms 2260 KB Output is correct
25 Correct 22 ms 2256 KB Output is correct
26 Correct 20 ms 2388 KB Output is correct
27 Correct 20 ms 2396 KB Output is correct
28 Correct 19 ms 2140 KB Output is correct
29 Correct 19 ms 2124 KB Output is correct
30 Correct 20 ms 2380 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 456 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 5 ms 756 KB Output is correct
38 Correct 6 ms 896 KB Output is correct
39 Correct 11 ms 1112 KB Output is correct
40 Correct 26 ms 2016 KB Output is correct
41 Correct 33 ms 2760 KB Output is correct
42 Correct 31 ms 2804 KB Output is correct
43 Correct 30 ms 2756 KB Output is correct
44 Correct 31 ms 2632 KB Output is correct
45 Correct 30 ms 2648 KB Output is correct
46 Correct 32 ms 2652 KB Output is correct
47 Correct 32 ms 2652 KB Output is correct
48 Correct 31 ms 2648 KB Output is correct
49 Correct 31 ms 2652 KB Output is correct
50 Correct 32 ms 2652 KB Output is correct
51 Correct 30 ms 2816 KB Output is correct
52 Correct 36 ms 2652 KB Output is correct
53 Correct 32 ms 2648 KB Output is correct
54 Correct 31 ms 2648 KB Output is correct
55 Correct 30 ms 2652 KB Output is correct
56 Correct 31 ms 2648 KB Output is correct
57 Correct 31 ms 2652 KB Output is correct
58 Correct 30 ms 2820 KB Output is correct
59 Correct 31 ms 2652 KB Output is correct
60 Correct 31 ms 2628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 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 348 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 844 KB Output is correct
15 Correct 10 ms 1232 KB Output is correct
16 Correct 17 ms 2256 KB Output is correct
17 Correct 15 ms 2140 KB Output is correct
18 Correct 17 ms 2140 KB Output is correct
19 Correct 22 ms 2392 KB Output is correct
20 Correct 17 ms 2140 KB Output is correct
21 Correct 17 ms 2140 KB Output is correct
22 Correct 17 ms 2296 KB Output is correct
23 Correct 17 ms 2280 KB Output is correct
24 Correct 17 ms 2252 KB Output is correct
25 Correct 18 ms 2140 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 7 ms 1116 KB Output is correct
30 Correct 14 ms 1628 KB Output is correct
31 Correct 19 ms 2440 KB Output is correct
32 Correct 20 ms 2396 KB Output is correct
33 Correct 19 ms 2396 KB Output is correct
34 Correct 20 ms 2260 KB Output is correct
35 Correct 22 ms 2256 KB Output is correct
36 Correct 20 ms 2388 KB Output is correct
37 Correct 20 ms 2396 KB Output is correct
38 Correct 19 ms 2140 KB Output is correct
39 Correct 19 ms 2124 KB Output is correct
40 Correct 20 ms 2380 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 456 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 3 ms 344 KB Output is correct
47 Correct 5 ms 756 KB Output is correct
48 Correct 6 ms 896 KB Output is correct
49 Correct 11 ms 1112 KB Output is correct
50 Correct 26 ms 2016 KB Output is correct
51 Correct 33 ms 2760 KB Output is correct
52 Correct 31 ms 2804 KB Output is correct
53 Correct 30 ms 2756 KB Output is correct
54 Correct 31 ms 2632 KB Output is correct
55 Correct 30 ms 2648 KB Output is correct
56 Correct 32 ms 2652 KB Output is correct
57 Correct 32 ms 2652 KB Output is correct
58 Correct 31 ms 2648 KB Output is correct
59 Correct 31 ms 2652 KB Output is correct
60 Correct 32 ms 2652 KB Output is correct
61 Correct 30 ms 2816 KB Output is correct
62 Correct 36 ms 2652 KB Output is correct
63 Correct 32 ms 2648 KB Output is correct
64 Correct 31 ms 2648 KB Output is correct
65 Correct 30 ms 2652 KB Output is correct
66 Correct 31 ms 2648 KB Output is correct
67 Correct 31 ms 2652 KB Output is correct
68 Correct 30 ms 2820 KB Output is correct
69 Correct 31 ms 2652 KB Output is correct
70 Correct 31 ms 2628 KB Output is correct
71 Correct 10 ms 860 KB Output is correct
72 Correct 10 ms 984 KB Output is correct
73 Correct 10 ms 860 KB Output is correct
74 Correct 10 ms 756 KB Output is correct
75 Correct 10 ms 864 KB Output is correct
76 Correct 35 ms 1476 KB Output is correct
77 Correct 42 ms 1372 KB Output is correct
78 Correct 34 ms 1404 KB Output is correct
79 Correct 36 ms 1372 KB Output is correct
80 Correct 34 ms 1372 KB Output is correct
81 Correct 113 ms 2632 KB Output is correct
82 Correct 112 ms 2748 KB Output is correct
83 Correct 112 ms 2640 KB Output is correct
84 Correct 112 ms 2640 KB Output is correct
85 Correct 143 ms 2756 KB Output is correct
86 Correct 366 ms 3408 KB Output is correct
87 Correct 373 ms 3436 KB Output is correct
88 Correct 371 ms 3432 KB Output is correct
89 Correct 368 ms 3324 KB Output is correct
90 Correct 364 ms 3436 KB Output is correct
91 Execution timed out 7039 ms 8852 KB Time limit exceeded
92 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 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 348 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 844 KB Output is correct
15 Correct 10 ms 1232 KB Output is correct
16 Correct 17 ms 2256 KB Output is correct
17 Correct 15 ms 2140 KB Output is correct
18 Correct 17 ms 2140 KB Output is correct
19 Correct 22 ms 2392 KB Output is correct
20 Correct 17 ms 2140 KB Output is correct
21 Correct 17 ms 2140 KB Output is correct
22 Correct 17 ms 2296 KB Output is correct
23 Correct 17 ms 2280 KB Output is correct
24 Correct 17 ms 2252 KB Output is correct
25 Correct 18 ms 2140 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 7 ms 1116 KB Output is correct
30 Correct 14 ms 1628 KB Output is correct
31 Correct 19 ms 2440 KB Output is correct
32 Correct 20 ms 2396 KB Output is correct
33 Correct 19 ms 2396 KB Output is correct
34 Correct 20 ms 2260 KB Output is correct
35 Correct 22 ms 2256 KB Output is correct
36 Correct 20 ms 2388 KB Output is correct
37 Correct 20 ms 2396 KB Output is correct
38 Correct 19 ms 2140 KB Output is correct
39 Correct 19 ms 2124 KB Output is correct
40 Correct 20 ms 2380 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 456 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 3 ms 344 KB Output is correct
47 Correct 5 ms 756 KB Output is correct
48 Correct 6 ms 896 KB Output is correct
49 Correct 11 ms 1112 KB Output is correct
50 Correct 26 ms 2016 KB Output is correct
51 Correct 33 ms 2760 KB Output is correct
52 Correct 31 ms 2804 KB Output is correct
53 Correct 30 ms 2756 KB Output is correct
54 Correct 31 ms 2632 KB Output is correct
55 Correct 30 ms 2648 KB Output is correct
56 Correct 32 ms 2652 KB Output is correct
57 Correct 32 ms 2652 KB Output is correct
58 Correct 31 ms 2648 KB Output is correct
59 Correct 31 ms 2652 KB Output is correct
60 Correct 32 ms 2652 KB Output is correct
61 Correct 30 ms 2816 KB Output is correct
62 Correct 36 ms 2652 KB Output is correct
63 Correct 32 ms 2648 KB Output is correct
64 Correct 31 ms 2648 KB Output is correct
65 Correct 30 ms 2652 KB Output is correct
66 Correct 31 ms 2648 KB Output is correct
67 Correct 31 ms 2652 KB Output is correct
68 Correct 30 ms 2820 KB Output is correct
69 Correct 31 ms 2652 KB Output is correct
70 Correct 31 ms 2628 KB Output is correct
71 Correct 10 ms 860 KB Output is correct
72 Correct 10 ms 984 KB Output is correct
73 Correct 10 ms 860 KB Output is correct
74 Correct 10 ms 756 KB Output is correct
75 Correct 10 ms 864 KB Output is correct
76 Correct 35 ms 1476 KB Output is correct
77 Correct 42 ms 1372 KB Output is correct
78 Correct 34 ms 1404 KB Output is correct
79 Correct 36 ms 1372 KB Output is correct
80 Correct 34 ms 1372 KB Output is correct
81 Correct 113 ms 2632 KB Output is correct
82 Correct 112 ms 2748 KB Output is correct
83 Correct 112 ms 2640 KB Output is correct
84 Correct 112 ms 2640 KB Output is correct
85 Correct 143 ms 2756 KB Output is correct
86 Correct 366 ms 3408 KB Output is correct
87 Correct 373 ms 3436 KB Output is correct
88 Correct 371 ms 3432 KB Output is correct
89 Correct 368 ms 3324 KB Output is correct
90 Correct 364 ms 3436 KB Output is correct
91 Execution timed out 7039 ms 8852 KB Time limit exceeded
92 Halted 0 ms 0 KB -