답안 #569483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569483 2022-05-27T12:24:23 Z aryan12 Diversity (CEOI21_diversity) C++17
64 / 100
58 ms 14028 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3e5 + 5;

void Solve() 
{
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	vector<int> cnt(N, 0);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	vector<int> idx(N, 0);
	for(int i = 0; i < N; i++)
	{
		idx[i] = i;
	}
	sort(idx.begin(), idx.end(), [&](int i, int j)
	{
		return cnt[i] < cnt[j];
	});
	vector<int> ans(N);
	int l = 1, r = n;
	cin >> l >> r;
	for(int i = 1; i <= N; i++)
	{
		for(int j = 0; j < cnt[idx[i]]; j++)
		{
			if(i % 2 == 1) ans[l++] = idx[i];
			else ans[r--] = idx[i];
		}
	}
	reverse(ans.begin() + 1, ans.begin() + 1 + n);
	vector<int> sum(n + 2, 0);
	sum[n + 1] = 0;
	for(int i = n; i > 0; i--)
	{
		sum[i] = sum[i + 1] + 1;
		if(i == n || ans[i] != ans[i + 1])
		{
			sum[i] += (n - i);
		}
	}
	int res = 0;
	for(int i = 1; i <= n; i++)
	{
		res += sum[i];
	}
	cout << res << "\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7336 KB Output is correct
2 Correct 16 ms 7328 KB Output is correct
3 Correct 9 ms 7252 KB Output is correct
4 Correct 9 ms 7340 KB Output is correct
5 Correct 17 ms 7332 KB Output is correct
6 Correct 10 ms 7364 KB Output is correct
7 Correct 16 ms 7252 KB Output is correct
8 Correct 10 ms 7332 KB Output is correct
9 Correct 10 ms 7340 KB Output is correct
10 Correct 10 ms 7336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7328 KB Output is correct
2 Correct 17 ms 7356 KB Output is correct
3 Correct 11 ms 7432 KB Output is correct
4 Correct 16 ms 9088 KB Output is correct
5 Correct 31 ms 10828 KB Output is correct
6 Correct 30 ms 12704 KB Output is correct
7 Correct 43 ms 12620 KB Output is correct
8 Correct 28 ms 12564 KB Output is correct
9 Correct 32 ms 12604 KB Output is correct
10 Correct 35 ms 12724 KB Output is correct
11 Correct 33 ms 12688 KB Output is correct
12 Correct 29 ms 12664 KB Output is correct
13 Correct 27 ms 12676 KB Output is correct
14 Correct 31 ms 12608 KB Output is correct
15 Correct 35 ms 12692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7328 KB Output is correct
2 Correct 17 ms 7356 KB Output is correct
3 Correct 11 ms 7432 KB Output is correct
4 Correct 16 ms 9088 KB Output is correct
5 Correct 31 ms 10828 KB Output is correct
6 Correct 30 ms 12704 KB Output is correct
7 Correct 43 ms 12620 KB Output is correct
8 Correct 28 ms 12564 KB Output is correct
9 Correct 32 ms 12604 KB Output is correct
10 Correct 35 ms 12724 KB Output is correct
11 Correct 33 ms 12688 KB Output is correct
12 Correct 29 ms 12664 KB Output is correct
13 Correct 27 ms 12676 KB Output is correct
14 Correct 31 ms 12608 KB Output is correct
15 Correct 35 ms 12692 KB Output is correct
16 Correct 11 ms 7380 KB Output is correct
17 Correct 18 ms 7352 KB Output is correct
18 Correct 16 ms 7508 KB Output is correct
19 Correct 19 ms 9156 KB Output is correct
20 Correct 26 ms 10920 KB Output is correct
21 Correct 32 ms 12876 KB Output is correct
22 Correct 46 ms 12820 KB Output is correct
23 Correct 35 ms 12812 KB Output is correct
24 Correct 35 ms 12816 KB Output is correct
25 Correct 37 ms 12820 KB Output is correct
26 Correct 31 ms 12828 KB Output is correct
27 Correct 29 ms 12764 KB Output is correct
28 Correct 29 ms 12764 KB Output is correct
29 Correct 32 ms 12720 KB Output is correct
30 Correct 32 ms 12816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7328 KB Output is correct
2 Correct 17 ms 7356 KB Output is correct
3 Correct 11 ms 7432 KB Output is correct
4 Correct 16 ms 9088 KB Output is correct
5 Correct 31 ms 10828 KB Output is correct
6 Correct 30 ms 12704 KB Output is correct
7 Correct 43 ms 12620 KB Output is correct
8 Correct 28 ms 12564 KB Output is correct
9 Correct 32 ms 12604 KB Output is correct
10 Correct 35 ms 12724 KB Output is correct
11 Correct 33 ms 12688 KB Output is correct
12 Correct 29 ms 12664 KB Output is correct
13 Correct 27 ms 12676 KB Output is correct
14 Correct 31 ms 12608 KB Output is correct
15 Correct 35 ms 12692 KB Output is correct
16 Correct 11 ms 7380 KB Output is correct
17 Correct 18 ms 7352 KB Output is correct
18 Correct 16 ms 7508 KB Output is correct
19 Correct 19 ms 9156 KB Output is correct
20 Correct 26 ms 10920 KB Output is correct
21 Correct 32 ms 12876 KB Output is correct
22 Correct 46 ms 12820 KB Output is correct
23 Correct 35 ms 12812 KB Output is correct
24 Correct 35 ms 12816 KB Output is correct
25 Correct 37 ms 12820 KB Output is correct
26 Correct 31 ms 12828 KB Output is correct
27 Correct 29 ms 12764 KB Output is correct
28 Correct 29 ms 12764 KB Output is correct
29 Correct 32 ms 12720 KB Output is correct
30 Correct 32 ms 12816 KB Output is correct
31 Correct 10 ms 7344 KB Output is correct
32 Correct 11 ms 7380 KB Output is correct
33 Correct 11 ms 7344 KB Output is correct
34 Correct 11 ms 7508 KB Output is correct
35 Correct 10 ms 7508 KB Output is correct
36 Correct 9 ms 7452 KB Output is correct
37 Correct 14 ms 8276 KB Output is correct
38 Correct 17 ms 8292 KB Output is correct
39 Correct 24 ms 9212 KB Output is correct
40 Correct 26 ms 11260 KB Output is correct
41 Correct 43 ms 13080 KB Output is correct
42 Correct 30 ms 13084 KB Output is correct
43 Correct 31 ms 13204 KB Output is correct
44 Correct 31 ms 13136 KB Output is correct
45 Correct 31 ms 13132 KB Output is correct
46 Correct 34 ms 13144 KB Output is correct
47 Correct 32 ms 13132 KB Output is correct
48 Correct 32 ms 13132 KB Output is correct
49 Correct 33 ms 13192 KB Output is correct
50 Correct 32 ms 13208 KB Output is correct
51 Correct 33 ms 13196 KB Output is correct
52 Correct 32 ms 13196 KB Output is correct
53 Correct 34 ms 13204 KB Output is correct
54 Correct 34 ms 13184 KB Output is correct
55 Correct 32 ms 13200 KB Output is correct
56 Correct 31 ms 13196 KB Output is correct
57 Correct 32 ms 13204 KB Output is correct
58 Correct 36 ms 13116 KB Output is correct
59 Correct 31 ms 13208 KB Output is correct
60 Correct 35 ms 13204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7336 KB Output is correct
2 Correct 16 ms 7328 KB Output is correct
3 Correct 9 ms 7252 KB Output is correct
4 Correct 9 ms 7340 KB Output is correct
5 Correct 17 ms 7332 KB Output is correct
6 Correct 10 ms 7364 KB Output is correct
7 Correct 16 ms 7252 KB Output is correct
8 Correct 10 ms 7332 KB Output is correct
9 Correct 10 ms 7340 KB Output is correct
10 Correct 10 ms 7336 KB Output is correct
11 Correct 10 ms 7328 KB Output is correct
12 Correct 17 ms 7356 KB Output is correct
13 Correct 11 ms 7432 KB Output is correct
14 Correct 16 ms 9088 KB Output is correct
15 Correct 31 ms 10828 KB Output is correct
16 Correct 30 ms 12704 KB Output is correct
17 Correct 43 ms 12620 KB Output is correct
18 Correct 28 ms 12564 KB Output is correct
19 Correct 32 ms 12604 KB Output is correct
20 Correct 35 ms 12724 KB Output is correct
21 Correct 33 ms 12688 KB Output is correct
22 Correct 29 ms 12664 KB Output is correct
23 Correct 27 ms 12676 KB Output is correct
24 Correct 31 ms 12608 KB Output is correct
25 Correct 35 ms 12692 KB Output is correct
26 Correct 11 ms 7380 KB Output is correct
27 Correct 18 ms 7352 KB Output is correct
28 Correct 16 ms 7508 KB Output is correct
29 Correct 19 ms 9156 KB Output is correct
30 Correct 26 ms 10920 KB Output is correct
31 Correct 32 ms 12876 KB Output is correct
32 Correct 46 ms 12820 KB Output is correct
33 Correct 35 ms 12812 KB Output is correct
34 Correct 35 ms 12816 KB Output is correct
35 Correct 37 ms 12820 KB Output is correct
36 Correct 31 ms 12828 KB Output is correct
37 Correct 29 ms 12764 KB Output is correct
38 Correct 29 ms 12764 KB Output is correct
39 Correct 32 ms 12720 KB Output is correct
40 Correct 32 ms 12816 KB Output is correct
41 Correct 10 ms 7344 KB Output is correct
42 Correct 11 ms 7380 KB Output is correct
43 Correct 11 ms 7344 KB Output is correct
44 Correct 11 ms 7508 KB Output is correct
45 Correct 10 ms 7508 KB Output is correct
46 Correct 9 ms 7452 KB Output is correct
47 Correct 14 ms 8276 KB Output is correct
48 Correct 17 ms 8292 KB Output is correct
49 Correct 24 ms 9212 KB Output is correct
50 Correct 26 ms 11260 KB Output is correct
51 Correct 43 ms 13080 KB Output is correct
52 Correct 30 ms 13084 KB Output is correct
53 Correct 31 ms 13204 KB Output is correct
54 Correct 31 ms 13136 KB Output is correct
55 Correct 31 ms 13132 KB Output is correct
56 Correct 34 ms 13144 KB Output is correct
57 Correct 32 ms 13132 KB Output is correct
58 Correct 32 ms 13132 KB Output is correct
59 Correct 33 ms 13192 KB Output is correct
60 Correct 32 ms 13208 KB Output is correct
61 Correct 33 ms 13196 KB Output is correct
62 Correct 32 ms 13196 KB Output is correct
63 Correct 34 ms 13204 KB Output is correct
64 Correct 34 ms 13184 KB Output is correct
65 Correct 32 ms 13200 KB Output is correct
66 Correct 31 ms 13196 KB Output is correct
67 Correct 32 ms 13204 KB Output is correct
68 Correct 36 ms 13116 KB Output is correct
69 Correct 31 ms 13208 KB Output is correct
70 Correct 35 ms 13204 KB Output is correct
71 Correct 15 ms 8276 KB Output is correct
72 Correct 14 ms 8404 KB Output is correct
73 Correct 19 ms 8340 KB Output is correct
74 Correct 13 ms 8304 KB Output is correct
75 Correct 14 ms 8276 KB Output is correct
76 Correct 18 ms 9316 KB Output is correct
77 Correct 18 ms 9400 KB Output is correct
78 Correct 17 ms 9300 KB Output is correct
79 Correct 25 ms 9332 KB Output is correct
80 Correct 20 ms 9312 KB Output is correct
81 Correct 28 ms 11400 KB Output is correct
82 Correct 26 ms 11400 KB Output is correct
83 Correct 25 ms 11388 KB Output is correct
84 Correct 25 ms 11404 KB Output is correct
85 Correct 26 ms 11400 KB Output is correct
86 Correct 30 ms 11488 KB Output is correct
87 Correct 32 ms 11528 KB Output is correct
88 Correct 29 ms 11520 KB Output is correct
89 Correct 27 ms 11468 KB Output is correct
90 Correct 27 ms 11528 KB Output is correct
91 Correct 37 ms 13704 KB Output is correct
92 Correct 39 ms 13744 KB Output is correct
93 Correct 41 ms 13772 KB Output is correct
94 Correct 39 ms 13764 KB Output is correct
95 Correct 40 ms 13712 KB Output is correct
96 Correct 44 ms 13860 KB Output is correct
97 Correct 42 ms 13900 KB Output is correct
98 Correct 45 ms 13948 KB Output is correct
99 Correct 57 ms 13840 KB Output is correct
100 Correct 42 ms 13848 KB Output is correct
101 Correct 42 ms 14028 KB Output is correct
102 Correct 54 ms 13864 KB Output is correct
103 Correct 42 ms 13844 KB Output is correct
104 Correct 40 ms 13840 KB Output is correct
105 Correct 42 ms 13832 KB Output is correct
106 Correct 43 ms 13964 KB Output is correct
107 Correct 43 ms 13904 KB Output is correct
108 Correct 40 ms 13972 KB Output is correct
109 Correct 45 ms 13980 KB Output is correct
110 Correct 52 ms 13960 KB Output is correct
111 Correct 48 ms 13972 KB Output is correct
112 Correct 49 ms 13960 KB Output is correct
113 Correct 42 ms 13900 KB Output is correct
114 Correct 55 ms 13900 KB Output is correct
115 Correct 58 ms 13976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7336 KB Output is correct
2 Correct 16 ms 7328 KB Output is correct
3 Correct 9 ms 7252 KB Output is correct
4 Correct 9 ms 7340 KB Output is correct
5 Correct 17 ms 7332 KB Output is correct
6 Correct 10 ms 7364 KB Output is correct
7 Correct 16 ms 7252 KB Output is correct
8 Correct 10 ms 7332 KB Output is correct
9 Correct 10 ms 7340 KB Output is correct
10 Correct 10 ms 7336 KB Output is correct
11 Correct 10 ms 7328 KB Output is correct
12 Correct 17 ms 7356 KB Output is correct
13 Correct 11 ms 7432 KB Output is correct
14 Correct 16 ms 9088 KB Output is correct
15 Correct 31 ms 10828 KB Output is correct
16 Correct 30 ms 12704 KB Output is correct
17 Correct 43 ms 12620 KB Output is correct
18 Correct 28 ms 12564 KB Output is correct
19 Correct 32 ms 12604 KB Output is correct
20 Correct 35 ms 12724 KB Output is correct
21 Correct 33 ms 12688 KB Output is correct
22 Correct 29 ms 12664 KB Output is correct
23 Correct 27 ms 12676 KB Output is correct
24 Correct 31 ms 12608 KB Output is correct
25 Correct 35 ms 12692 KB Output is correct
26 Correct 11 ms 7380 KB Output is correct
27 Correct 18 ms 7352 KB Output is correct
28 Correct 16 ms 7508 KB Output is correct
29 Correct 19 ms 9156 KB Output is correct
30 Correct 26 ms 10920 KB Output is correct
31 Correct 32 ms 12876 KB Output is correct
32 Correct 46 ms 12820 KB Output is correct
33 Correct 35 ms 12812 KB Output is correct
34 Correct 35 ms 12816 KB Output is correct
35 Correct 37 ms 12820 KB Output is correct
36 Correct 31 ms 12828 KB Output is correct
37 Correct 29 ms 12764 KB Output is correct
38 Correct 29 ms 12764 KB Output is correct
39 Correct 32 ms 12720 KB Output is correct
40 Correct 32 ms 12816 KB Output is correct
41 Correct 10 ms 7344 KB Output is correct
42 Correct 11 ms 7380 KB Output is correct
43 Correct 11 ms 7344 KB Output is correct
44 Correct 11 ms 7508 KB Output is correct
45 Correct 10 ms 7508 KB Output is correct
46 Correct 9 ms 7452 KB Output is correct
47 Correct 14 ms 8276 KB Output is correct
48 Correct 17 ms 8292 KB Output is correct
49 Correct 24 ms 9212 KB Output is correct
50 Correct 26 ms 11260 KB Output is correct
51 Correct 43 ms 13080 KB Output is correct
52 Correct 30 ms 13084 KB Output is correct
53 Correct 31 ms 13204 KB Output is correct
54 Correct 31 ms 13136 KB Output is correct
55 Correct 31 ms 13132 KB Output is correct
56 Correct 34 ms 13144 KB Output is correct
57 Correct 32 ms 13132 KB Output is correct
58 Correct 32 ms 13132 KB Output is correct
59 Correct 33 ms 13192 KB Output is correct
60 Correct 32 ms 13208 KB Output is correct
61 Correct 33 ms 13196 KB Output is correct
62 Correct 32 ms 13196 KB Output is correct
63 Correct 34 ms 13204 KB Output is correct
64 Correct 34 ms 13184 KB Output is correct
65 Correct 32 ms 13200 KB Output is correct
66 Correct 31 ms 13196 KB Output is correct
67 Correct 32 ms 13204 KB Output is correct
68 Correct 36 ms 13116 KB Output is correct
69 Correct 31 ms 13208 KB Output is correct
70 Correct 35 ms 13204 KB Output is correct
71 Correct 15 ms 8276 KB Output is correct
72 Correct 14 ms 8404 KB Output is correct
73 Correct 19 ms 8340 KB Output is correct
74 Correct 13 ms 8304 KB Output is correct
75 Correct 14 ms 8276 KB Output is correct
76 Correct 18 ms 9316 KB Output is correct
77 Correct 18 ms 9400 KB Output is correct
78 Correct 17 ms 9300 KB Output is correct
79 Correct 25 ms 9332 KB Output is correct
80 Correct 20 ms 9312 KB Output is correct
81 Correct 28 ms 11400 KB Output is correct
82 Correct 26 ms 11400 KB Output is correct
83 Correct 25 ms 11388 KB Output is correct
84 Correct 25 ms 11404 KB Output is correct
85 Correct 26 ms 11400 KB Output is correct
86 Correct 30 ms 11488 KB Output is correct
87 Correct 32 ms 11528 KB Output is correct
88 Correct 29 ms 11520 KB Output is correct
89 Correct 27 ms 11468 KB Output is correct
90 Correct 27 ms 11528 KB Output is correct
91 Correct 37 ms 13704 KB Output is correct
92 Correct 39 ms 13744 KB Output is correct
93 Correct 41 ms 13772 KB Output is correct
94 Correct 39 ms 13764 KB Output is correct
95 Correct 40 ms 13712 KB Output is correct
96 Correct 44 ms 13860 KB Output is correct
97 Correct 42 ms 13900 KB Output is correct
98 Correct 45 ms 13948 KB Output is correct
99 Correct 57 ms 13840 KB Output is correct
100 Correct 42 ms 13848 KB Output is correct
101 Correct 42 ms 14028 KB Output is correct
102 Correct 54 ms 13864 KB Output is correct
103 Correct 42 ms 13844 KB Output is correct
104 Correct 40 ms 13840 KB Output is correct
105 Correct 42 ms 13832 KB Output is correct
106 Correct 43 ms 13964 KB Output is correct
107 Correct 43 ms 13904 KB Output is correct
108 Correct 40 ms 13972 KB Output is correct
109 Correct 45 ms 13980 KB Output is correct
110 Correct 52 ms 13960 KB Output is correct
111 Correct 48 ms 13972 KB Output is correct
112 Correct 49 ms 13960 KB Output is correct
113 Correct 42 ms 13900 KB Output is correct
114 Correct 55 ms 13900 KB Output is correct
115 Correct 58 ms 13976 KB Output is correct
116 Incorrect 13 ms 7636 KB Output isn't correct
117 Halted 0 ms 0 KB -