답안 #952981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952981 2024-03-25T08:36:01 Z Sacharlemagne Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 39332 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll cost(vector<int> v) {
		ll ans = 0;
		map<ll,ll> last;
		for (ll i = 0; i<v.size(); ++i) {
			int bef = last[v[i]];
			ans += (i-bef+1)*(v.size()-i);
			last[v[i]] = i+1;
		}

	return ans;
}
int main() {
	/*vector<int> v = {1,2,2,3,3,3,5,5,5,6,6,4};
	cout << cost(v);*/

	//ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int n,q; cin >> n >> q;
	vector<int> vv(n); for (int i = 0; i<n; ++i) cin >> vv[i];
	while (q--) {
		int L, R;
		cin >> L >> R;
		--L; --R;
		vector<int> vvv(R-L+1); for (int i = 0; i<R-L+1; ++i) vvv[i] = vv[i+L];
		map<ll,ll> m; for (int &i : vvv) ++m[i];
		vector<int> a; for (auto p : m) a.push_back(p.second);
		sort(a.begin(), a.end());
		vector<int> v(R-L+1); ll l = 0, r = R-L;
		for (int i = 0; i<a.size(); ++i) {
			if (i%2) {
				for (int L = 0; L<a[i]; ++L) v[l+L] = i;
				l += a[i];
			}
			else {
				for (int R = 0; R<a[i]; ++R) v[r-R] = i;
				r -= a[i];
			}
		}
		ll fin = cost(v);
		cout << fin << '\n';
	}
	return 0;
}
/*
 1 2 2 3 3 3 5 5 5 6 6 4
 */

Compilation message

diversity.cpp: In function 'll cost(std::vector<int>)':
diversity.cpp:8:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   for (ll i = 0; i<v.size(); ++i) {
      |                  ~^~~~~~~~~
diversity.cpp: In function 'int main()':
diversity.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int i = 0; i<a.size(); ++i) {
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 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 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 26 ms 3932 KB Output is correct
6 Correct 42 ms 5560 KB Output is correct
7 Correct 39 ms 5712 KB Output is correct
8 Correct 40 ms 5716 KB Output is correct
9 Correct 41 ms 5716 KB Output is correct
10 Correct 42 ms 5568 KB Output is correct
11 Correct 42 ms 5716 KB Output is correct
12 Correct 55 ms 5716 KB Output is correct
13 Correct 41 ms 5716 KB Output is correct
14 Correct 40 ms 5556 KB Output is correct
15 Correct 42 ms 5572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 26 ms 3932 KB Output is correct
6 Correct 42 ms 5560 KB Output is correct
7 Correct 39 ms 5712 KB Output is correct
8 Correct 40 ms 5716 KB Output is correct
9 Correct 41 ms 5716 KB Output is correct
10 Correct 42 ms 5568 KB Output is correct
11 Correct 42 ms 5716 KB Output is correct
12 Correct 55 ms 5716 KB Output is correct
13 Correct 41 ms 5716 KB Output is correct
14 Correct 40 ms 5556 KB Output is correct
15 Correct 42 ms 5572 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 16 ms 2132 KB Output is correct
20 Correct 31 ms 3932 KB Output is correct
21 Correct 47 ms 5892 KB Output is correct
22 Correct 47 ms 5712 KB Output is correct
23 Correct 47 ms 5712 KB Output is correct
24 Correct 47 ms 5724 KB Output is correct
25 Correct 48 ms 5684 KB Output is correct
26 Correct 47 ms 5720 KB Output is correct
27 Correct 47 ms 5724 KB Output is correct
28 Correct 45 ms 5660 KB Output is correct
29 Correct 46 ms 5716 KB Output is correct
30 Correct 48 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 16 ms 2140 KB Output is correct
5 Correct 26 ms 3932 KB Output is correct
6 Correct 42 ms 5560 KB Output is correct
7 Correct 39 ms 5712 KB Output is correct
8 Correct 40 ms 5716 KB Output is correct
9 Correct 41 ms 5716 KB Output is correct
10 Correct 42 ms 5568 KB Output is correct
11 Correct 42 ms 5716 KB Output is correct
12 Correct 55 ms 5716 KB Output is correct
13 Correct 41 ms 5716 KB Output is correct
14 Correct 40 ms 5556 KB Output is correct
15 Correct 42 ms 5572 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 16 ms 2132 KB Output is correct
20 Correct 31 ms 3932 KB Output is correct
21 Correct 47 ms 5892 KB Output is correct
22 Correct 47 ms 5712 KB Output is correct
23 Correct 47 ms 5712 KB Output is correct
24 Correct 47 ms 5724 KB Output is correct
25 Correct 48 ms 5684 KB Output is correct
26 Correct 47 ms 5720 KB Output is correct
27 Correct 47 ms 5724 KB Output is correct
28 Correct 45 ms 5660 KB Output is correct
29 Correct 46 ms 5716 KB Output is correct
30 Correct 48 ms 5712 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 3 ms 604 KB Output is correct
37 Correct 11 ms 1344 KB Output is correct
38 Correct 12 ms 1348 KB Output is correct
39 Correct 23 ms 2396 KB Output is correct
40 Correct 45 ms 4272 KB Output is correct
41 Correct 71 ms 6592 KB Output is correct
42 Correct 67 ms 6224 KB Output is correct
43 Correct 68 ms 6312 KB Output is correct
44 Correct 66 ms 6228 KB Output is correct
45 Correct 67 ms 6228 KB Output is correct
46 Correct 71 ms 6192 KB Output is correct
47 Correct 67 ms 6200 KB Output is correct
48 Correct 69 ms 6228 KB Output is correct
49 Correct 66 ms 6208 KB Output is correct
50 Correct 67 ms 6284 KB Output is correct
51 Correct 69 ms 6460 KB Output is correct
52 Correct 67 ms 6228 KB Output is correct
53 Correct 81 ms 6360 KB Output is correct
54 Correct 67 ms 6280 KB Output is correct
55 Correct 66 ms 6192 KB Output is correct
56 Correct 66 ms 6336 KB Output is correct
57 Correct 66 ms 6228 KB Output is correct
58 Correct 66 ms 6332 KB Output is correct
59 Correct 69 ms 6288 KB Output is correct
60 Correct 66 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 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 432 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 16 ms 2140 KB Output is correct
15 Correct 26 ms 3932 KB Output is correct
16 Correct 42 ms 5560 KB Output is correct
17 Correct 39 ms 5712 KB Output is correct
18 Correct 40 ms 5716 KB Output is correct
19 Correct 41 ms 5716 KB Output is correct
20 Correct 42 ms 5568 KB Output is correct
21 Correct 42 ms 5716 KB Output is correct
22 Correct 55 ms 5716 KB Output is correct
23 Correct 41 ms 5716 KB Output is correct
24 Correct 40 ms 5556 KB Output is correct
25 Correct 42 ms 5572 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 16 ms 2132 KB Output is correct
30 Correct 31 ms 3932 KB Output is correct
31 Correct 47 ms 5892 KB Output is correct
32 Correct 47 ms 5712 KB Output is correct
33 Correct 47 ms 5712 KB Output is correct
34 Correct 47 ms 5724 KB Output is correct
35 Correct 48 ms 5684 KB Output is correct
36 Correct 47 ms 5720 KB Output is correct
37 Correct 47 ms 5724 KB Output is correct
38 Correct 45 ms 5660 KB Output is correct
39 Correct 46 ms 5716 KB Output is correct
40 Correct 48 ms 5712 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 11 ms 1344 KB Output is correct
48 Correct 12 ms 1348 KB Output is correct
49 Correct 23 ms 2396 KB Output is correct
50 Correct 45 ms 4272 KB Output is correct
51 Correct 71 ms 6592 KB Output is correct
52 Correct 67 ms 6224 KB Output is correct
53 Correct 68 ms 6312 KB Output is correct
54 Correct 66 ms 6228 KB Output is correct
55 Correct 67 ms 6228 KB Output is correct
56 Correct 71 ms 6192 KB Output is correct
57 Correct 67 ms 6200 KB Output is correct
58 Correct 69 ms 6228 KB Output is correct
59 Correct 66 ms 6208 KB Output is correct
60 Correct 67 ms 6284 KB Output is correct
61 Correct 69 ms 6460 KB Output is correct
62 Correct 67 ms 6228 KB Output is correct
63 Correct 81 ms 6360 KB Output is correct
64 Correct 67 ms 6280 KB Output is correct
65 Correct 66 ms 6192 KB Output is correct
66 Correct 66 ms 6336 KB Output is correct
67 Correct 66 ms 6228 KB Output is correct
68 Correct 66 ms 6332 KB Output is correct
69 Correct 69 ms 6288 KB Output is correct
70 Correct 66 ms 6224 KB Output is correct
71 Correct 13 ms 1628 KB Output is correct
72 Correct 14 ms 1624 KB Output is correct
73 Correct 14 ms 1628 KB Output is correct
74 Correct 18 ms 1636 KB Output is correct
75 Correct 14 ms 1624 KB Output is correct
76 Correct 32 ms 2908 KB Output is correct
77 Correct 32 ms 3092 KB Output is correct
78 Correct 32 ms 2900 KB Output is correct
79 Correct 35 ms 2904 KB Output is correct
80 Correct 36 ms 2896 KB Output is correct
81 Correct 72 ms 5652 KB Output is correct
82 Correct 84 ms 5716 KB Output is correct
83 Correct 70 ms 5692 KB Output is correct
84 Correct 71 ms 5712 KB Output is correct
85 Correct 75 ms 5712 KB Output is correct
86 Correct 84 ms 7160 KB Output is correct
87 Correct 86 ms 6996 KB Output is correct
88 Correct 88 ms 7076 KB Output is correct
89 Correct 83 ms 6992 KB Output is correct
90 Correct 83 ms 7092 KB Output is correct
91 Correct 179 ms 19692 KB Output is correct
92 Correct 184 ms 19660 KB Output is correct
93 Correct 176 ms 19660 KB Output is correct
94 Correct 188 ms 19660 KB Output is correct
95 Correct 176 ms 19628 KB Output is correct
96 Correct 244 ms 32784 KB Output is correct
97 Correct 234 ms 32720 KB Output is correct
98 Correct 238 ms 32856 KB Output is correct
99 Correct 232 ms 32808 KB Output is correct
100 Correct 260 ms 32720 KB Output is correct
101 Correct 240 ms 32948 KB Output is correct
102 Correct 257 ms 32716 KB Output is correct
103 Correct 235 ms 32680 KB Output is correct
104 Correct 284 ms 32720 KB Output is correct
105 Correct 246 ms 32720 KB Output is correct
106 Correct 273 ms 39112 KB Output is correct
107 Correct 266 ms 39092 KB Output is correct
108 Correct 281 ms 39332 KB Output is correct
109 Correct 283 ms 39112 KB Output is correct
110 Correct 263 ms 39112 KB Output is correct
111 Correct 269 ms 39284 KB Output is correct
112 Correct 248 ms 39196 KB Output is correct
113 Correct 276 ms 39212 KB Output is correct
114 Correct 295 ms 39208 KB Output is correct
115 Correct 282 ms 39096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 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 432 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 16 ms 2140 KB Output is correct
15 Correct 26 ms 3932 KB Output is correct
16 Correct 42 ms 5560 KB Output is correct
17 Correct 39 ms 5712 KB Output is correct
18 Correct 40 ms 5716 KB Output is correct
19 Correct 41 ms 5716 KB Output is correct
20 Correct 42 ms 5568 KB Output is correct
21 Correct 42 ms 5716 KB Output is correct
22 Correct 55 ms 5716 KB Output is correct
23 Correct 41 ms 5716 KB Output is correct
24 Correct 40 ms 5556 KB Output is correct
25 Correct 42 ms 5572 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 16 ms 2132 KB Output is correct
30 Correct 31 ms 3932 KB Output is correct
31 Correct 47 ms 5892 KB Output is correct
32 Correct 47 ms 5712 KB Output is correct
33 Correct 47 ms 5712 KB Output is correct
34 Correct 47 ms 5724 KB Output is correct
35 Correct 48 ms 5684 KB Output is correct
36 Correct 47 ms 5720 KB Output is correct
37 Correct 47 ms 5724 KB Output is correct
38 Correct 45 ms 5660 KB Output is correct
39 Correct 46 ms 5716 KB Output is correct
40 Correct 48 ms 5712 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 11 ms 1344 KB Output is correct
48 Correct 12 ms 1348 KB Output is correct
49 Correct 23 ms 2396 KB Output is correct
50 Correct 45 ms 4272 KB Output is correct
51 Correct 71 ms 6592 KB Output is correct
52 Correct 67 ms 6224 KB Output is correct
53 Correct 68 ms 6312 KB Output is correct
54 Correct 66 ms 6228 KB Output is correct
55 Correct 67 ms 6228 KB Output is correct
56 Correct 71 ms 6192 KB Output is correct
57 Correct 67 ms 6200 KB Output is correct
58 Correct 69 ms 6228 KB Output is correct
59 Correct 66 ms 6208 KB Output is correct
60 Correct 67 ms 6284 KB Output is correct
61 Correct 69 ms 6460 KB Output is correct
62 Correct 67 ms 6228 KB Output is correct
63 Correct 81 ms 6360 KB Output is correct
64 Correct 67 ms 6280 KB Output is correct
65 Correct 66 ms 6192 KB Output is correct
66 Correct 66 ms 6336 KB Output is correct
67 Correct 66 ms 6228 KB Output is correct
68 Correct 66 ms 6332 KB Output is correct
69 Correct 69 ms 6288 KB Output is correct
70 Correct 66 ms 6224 KB Output is correct
71 Correct 13 ms 1628 KB Output is correct
72 Correct 14 ms 1624 KB Output is correct
73 Correct 14 ms 1628 KB Output is correct
74 Correct 18 ms 1636 KB Output is correct
75 Correct 14 ms 1624 KB Output is correct
76 Correct 32 ms 2908 KB Output is correct
77 Correct 32 ms 3092 KB Output is correct
78 Correct 32 ms 2900 KB Output is correct
79 Correct 35 ms 2904 KB Output is correct
80 Correct 36 ms 2896 KB Output is correct
81 Correct 72 ms 5652 KB Output is correct
82 Correct 84 ms 5716 KB Output is correct
83 Correct 70 ms 5692 KB Output is correct
84 Correct 71 ms 5712 KB Output is correct
85 Correct 75 ms 5712 KB Output is correct
86 Correct 84 ms 7160 KB Output is correct
87 Correct 86 ms 6996 KB Output is correct
88 Correct 88 ms 7076 KB Output is correct
89 Correct 83 ms 6992 KB Output is correct
90 Correct 83 ms 7092 KB Output is correct
91 Correct 179 ms 19692 KB Output is correct
92 Correct 184 ms 19660 KB Output is correct
93 Correct 176 ms 19660 KB Output is correct
94 Correct 188 ms 19660 KB Output is correct
95 Correct 176 ms 19628 KB Output is correct
96 Correct 244 ms 32784 KB Output is correct
97 Correct 234 ms 32720 KB Output is correct
98 Correct 238 ms 32856 KB Output is correct
99 Correct 232 ms 32808 KB Output is correct
100 Correct 260 ms 32720 KB Output is correct
101 Correct 240 ms 32948 KB Output is correct
102 Correct 257 ms 32716 KB Output is correct
103 Correct 235 ms 32680 KB Output is correct
104 Correct 284 ms 32720 KB Output is correct
105 Correct 246 ms 32720 KB Output is correct
106 Correct 273 ms 39112 KB Output is correct
107 Correct 266 ms 39092 KB Output is correct
108 Correct 281 ms 39332 KB Output is correct
109 Correct 283 ms 39112 KB Output is correct
110 Correct 263 ms 39112 KB Output is correct
111 Correct 269 ms 39284 KB Output is correct
112 Correct 248 ms 39196 KB Output is correct
113 Correct 276 ms 39212 KB Output is correct
114 Correct 295 ms 39208 KB Output is correct
115 Correct 282 ms 39096 KB Output is correct
116 Execution timed out 7047 ms 1772 KB Time limit exceeded
117 Halted 0 ms 0 KB -