답안 #592392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
592392 2022-07-09T06:43:35 Z SeDunion Diversity (CEOI21_diversity) C++17
64 / 100
238 ms 20344 KB
#include <iostream>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#ifndef LOCAL
	#include <bits/stdc++.h>
	#define cerr if(false)cerr
#endif
 
using namespace std;
using ll = long long;
 
const int N = 1e6 + 66;
 
ll a[N], n;
 
ll pref[N];

/*
summa(a[i]*(a[i]+1)/2 + a[i]*pref[i-1]*(i+1) - a[i]*(pref[n-1]-pref[i])*i)
summa((a[i]^2+a[i])/2 + a[i]*pref[i-1]*i+a[i]*pref[i-1] - a[i]*(pref[n-1]-pref[i])*i)
summa((a[i]^2+a[i])/2 + a[i]*pref[i]*i-a[i]^2*i + a[i]*pref[i-1] - a[i]*(pref[n-1]-pref[i])*i)
summa((a[i]^2+a[i])/2 + a[i]*pref[i]*i-a[i]^2*i + a[i]*pref[i]-a[i]^2 - a[i]*(pref[n-1]-pref[i])*i)
summa((a[i]^2+a[i])/2 + a[i]*pref[i]*i-a[i]^2*i + a[i]*pref[i]-a[i]^2 - a[i]*pref[n-1]*i - a[i]*pref[i]*i)
summa((a[i]^2+a[i])/2 + a[i]*pref[i]*i - a[i]^2*i + a[i]*pref[i]-a[i]^2 - a[i]*pref[n-1]*i - a[i]*pref[i]*i)
summa(a[i]/2 + a[i]*pref[i]*(i+1) - a[i]^2*i - a[i]^2/2 - a[i]*pref[n-1]*i - a[i]*pref[i]*i)
summa(a[i]/2 + a[i]*pref[i] - a[i]^2*i - a[i]^2/2 - a[i]*pref[n-1]*i)
summa(a[i]/2 + a[i]*pref[i] - a[i]^2*i - a[i]^2/2 - a[i]*pref[n-1]*i)
 */

ll f(ll s) { return s * (s + 1) / 2; }

ll solve() {
	ll ans = 0;
	for (int i = 0 ; i < n ; ++ i) {
		pref[i] = a[i];
		if (i) pref[i] += pref[i - 1];
	}
	for (int i = 0 ; i < n ; ++ i) {
		if (i) ans += f(pref[i - 1]);
		ans += f(pref[n - 1] - pref[i]);
	}
	ll C = n * f(pref[n-1]);
	return C-ans;
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int q;
	cin >> n >> q;
	for (int i = 0 ; i < n ; ++ i) cin >> a[i];
	cin >> q >> q;
	map<int,int>mp;
	for (int i = 0 ; i < n ; ++ i) mp[a[i]]++;
	vector<int>freq;
	for (auto [f, s] : mp) freq.emplace_back(s);
	sort(freq.rbegin(), freq.rend());
	deque<int>p;
	for (int i : freq) {
		if ((int)p.size() & 1) p.push_back(i);
		else p.push_front(i);
	}
	n = p.size();
	for (int i = 0 ; i < n ; ++ i) a[i] = p[i];
	cout << solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 11 ms 1264 KB Output is correct
5 Correct 14 ms 2264 KB Output is correct
6 Correct 25 ms 3340 KB Output is correct
7 Correct 17 ms 3196 KB Output is correct
8 Correct 20 ms 3264 KB Output is correct
9 Correct 20 ms 3276 KB Output is correct
10 Correct 21 ms 3252 KB Output is correct
11 Correct 20 ms 3260 KB Output is correct
12 Correct 21 ms 3256 KB Output is correct
13 Correct 27 ms 3284 KB Output is correct
14 Correct 20 ms 3316 KB Output is correct
15 Correct 20 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 11 ms 1264 KB Output is correct
5 Correct 14 ms 2264 KB Output is correct
6 Correct 25 ms 3340 KB Output is correct
7 Correct 17 ms 3196 KB Output is correct
8 Correct 20 ms 3264 KB Output is correct
9 Correct 20 ms 3276 KB Output is correct
10 Correct 21 ms 3252 KB Output is correct
11 Correct 20 ms 3260 KB Output is correct
12 Correct 21 ms 3256 KB Output is correct
13 Correct 27 ms 3284 KB Output is correct
14 Correct 20 ms 3316 KB Output is correct
15 Correct 20 ms 3284 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 10 ms 1368 KB Output is correct
20 Correct 19 ms 2388 KB Output is correct
21 Correct 23 ms 3392 KB Output is correct
22 Correct 25 ms 3412 KB Output is correct
23 Correct 29 ms 3404 KB Output is correct
24 Correct 22 ms 3404 KB Output is correct
25 Correct 23 ms 3448 KB Output is correct
26 Correct 23 ms 3348 KB Output is correct
27 Correct 24 ms 3416 KB Output is correct
28 Correct 29 ms 3328 KB Output is correct
29 Correct 26 ms 3360 KB Output is correct
30 Correct 24 ms 3432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 11 ms 1264 KB Output is correct
5 Correct 14 ms 2264 KB Output is correct
6 Correct 25 ms 3340 KB Output is correct
7 Correct 17 ms 3196 KB Output is correct
8 Correct 20 ms 3264 KB Output is correct
9 Correct 20 ms 3276 KB Output is correct
10 Correct 21 ms 3252 KB Output is correct
11 Correct 20 ms 3260 KB Output is correct
12 Correct 21 ms 3256 KB Output is correct
13 Correct 27 ms 3284 KB Output is correct
14 Correct 20 ms 3316 KB Output is correct
15 Correct 20 ms 3284 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 10 ms 1368 KB Output is correct
20 Correct 19 ms 2388 KB Output is correct
21 Correct 23 ms 3392 KB Output is correct
22 Correct 25 ms 3412 KB Output is correct
23 Correct 29 ms 3404 KB Output is correct
24 Correct 22 ms 3404 KB Output is correct
25 Correct 23 ms 3448 KB Output is correct
26 Correct 23 ms 3348 KB Output is correct
27 Correct 24 ms 3416 KB Output is correct
28 Correct 29 ms 3328 KB Output is correct
29 Correct 26 ms 3360 KB Output is correct
30 Correct 24 ms 3432 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 6 ms 872 KB Output is correct
38 Correct 6 ms 872 KB Output is correct
39 Correct 14 ms 1512 KB Output is correct
40 Correct 32 ms 2644 KB Output is correct
41 Correct 38 ms 3788 KB Output is correct
42 Correct 37 ms 3880 KB Output is correct
43 Correct 36 ms 3856 KB Output is correct
44 Correct 36 ms 3868 KB Output is correct
45 Correct 37 ms 3872 KB Output is correct
46 Correct 35 ms 3804 KB Output is correct
47 Correct 35 ms 3792 KB Output is correct
48 Correct 48 ms 3860 KB Output is correct
49 Correct 46 ms 3864 KB Output is correct
50 Correct 41 ms 3800 KB Output is correct
51 Correct 36 ms 3792 KB Output is correct
52 Correct 40 ms 3872 KB Output is correct
53 Correct 37 ms 3864 KB Output is correct
54 Correct 36 ms 3796 KB Output is correct
55 Correct 36 ms 3792 KB Output is correct
56 Correct 35 ms 3880 KB Output is correct
57 Correct 42 ms 3820 KB Output is correct
58 Correct 39 ms 3864 KB Output is correct
59 Correct 39 ms 3784 KB Output is correct
60 Correct 38 ms 3800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 11 ms 1264 KB Output is correct
15 Correct 14 ms 2264 KB Output is correct
16 Correct 25 ms 3340 KB Output is correct
17 Correct 17 ms 3196 KB Output is correct
18 Correct 20 ms 3264 KB Output is correct
19 Correct 20 ms 3276 KB Output is correct
20 Correct 21 ms 3252 KB Output is correct
21 Correct 20 ms 3260 KB Output is correct
22 Correct 21 ms 3256 KB Output is correct
23 Correct 27 ms 3284 KB Output is correct
24 Correct 20 ms 3316 KB Output is correct
25 Correct 20 ms 3284 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 10 ms 1368 KB Output is correct
30 Correct 19 ms 2388 KB Output is correct
31 Correct 23 ms 3392 KB Output is correct
32 Correct 25 ms 3412 KB Output is correct
33 Correct 29 ms 3404 KB Output is correct
34 Correct 22 ms 3404 KB Output is correct
35 Correct 23 ms 3448 KB Output is correct
36 Correct 23 ms 3348 KB Output is correct
37 Correct 24 ms 3416 KB Output is correct
38 Correct 29 ms 3328 KB Output is correct
39 Correct 26 ms 3360 KB Output is correct
40 Correct 24 ms 3432 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 6 ms 872 KB Output is correct
48 Correct 6 ms 872 KB Output is correct
49 Correct 14 ms 1512 KB Output is correct
50 Correct 32 ms 2644 KB Output is correct
51 Correct 38 ms 3788 KB Output is correct
52 Correct 37 ms 3880 KB Output is correct
53 Correct 36 ms 3856 KB Output is correct
54 Correct 36 ms 3868 KB Output is correct
55 Correct 37 ms 3872 KB Output is correct
56 Correct 35 ms 3804 KB Output is correct
57 Correct 35 ms 3792 KB Output is correct
58 Correct 48 ms 3860 KB Output is correct
59 Correct 46 ms 3864 KB Output is correct
60 Correct 41 ms 3800 KB Output is correct
61 Correct 36 ms 3792 KB Output is correct
62 Correct 40 ms 3872 KB Output is correct
63 Correct 37 ms 3864 KB Output is correct
64 Correct 36 ms 3796 KB Output is correct
65 Correct 36 ms 3792 KB Output is correct
66 Correct 35 ms 3880 KB Output is correct
67 Correct 42 ms 3820 KB Output is correct
68 Correct 39 ms 3864 KB Output is correct
69 Correct 39 ms 3784 KB Output is correct
70 Correct 38 ms 3800 KB Output is correct
71 Correct 9 ms 1008 KB Output is correct
72 Correct 7 ms 980 KB Output is correct
73 Correct 8 ms 996 KB Output is correct
74 Correct 8 ms 1048 KB Output is correct
75 Correct 8 ms 980 KB Output is correct
76 Correct 16 ms 1876 KB Output is correct
77 Correct 16 ms 1912 KB Output is correct
78 Correct 21 ms 1868 KB Output is correct
79 Correct 18 ms 1840 KB Output is correct
80 Correct 17 ms 1888 KB Output is correct
81 Correct 37 ms 3416 KB Output is correct
82 Correct 36 ms 3448 KB Output is correct
83 Correct 37 ms 3444 KB Output is correct
84 Correct 35 ms 3424 KB Output is correct
85 Correct 36 ms 3432 KB Output is correct
86 Correct 56 ms 4140 KB Output is correct
87 Correct 54 ms 4176 KB Output is correct
88 Correct 46 ms 4232 KB Output is correct
89 Correct 45 ms 4300 KB Output is correct
90 Correct 45 ms 4256 KB Output is correct
91 Correct 109 ms 10612 KB Output is correct
92 Correct 101 ms 10648 KB Output is correct
93 Correct 105 ms 10632 KB Output is correct
94 Correct 111 ms 10684 KB Output is correct
95 Correct 114 ms 10596 KB Output is correct
96 Correct 175 ms 17040 KB Output is correct
97 Correct 171 ms 17124 KB Output is correct
98 Correct 207 ms 17076 KB Output is correct
99 Correct 150 ms 17060 KB Output is correct
100 Correct 152 ms 17040 KB Output is correct
101 Correct 178 ms 17164 KB Output is correct
102 Correct 184 ms 17088 KB Output is correct
103 Correct 147 ms 17100 KB Output is correct
104 Correct 177 ms 17084 KB Output is correct
105 Correct 168 ms 17084 KB Output is correct
106 Correct 209 ms 20280 KB Output is correct
107 Correct 198 ms 20312 KB Output is correct
108 Correct 208 ms 20344 KB Output is correct
109 Correct 184 ms 20304 KB Output is correct
110 Correct 179 ms 20292 KB Output is correct
111 Correct 238 ms 20220 KB Output is correct
112 Correct 225 ms 20320 KB Output is correct
113 Correct 176 ms 20236 KB Output is correct
114 Correct 223 ms 20276 KB Output is correct
115 Correct 180 ms 20252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 11 ms 1264 KB Output is correct
15 Correct 14 ms 2264 KB Output is correct
16 Correct 25 ms 3340 KB Output is correct
17 Correct 17 ms 3196 KB Output is correct
18 Correct 20 ms 3264 KB Output is correct
19 Correct 20 ms 3276 KB Output is correct
20 Correct 21 ms 3252 KB Output is correct
21 Correct 20 ms 3260 KB Output is correct
22 Correct 21 ms 3256 KB Output is correct
23 Correct 27 ms 3284 KB Output is correct
24 Correct 20 ms 3316 KB Output is correct
25 Correct 20 ms 3284 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 10 ms 1368 KB Output is correct
30 Correct 19 ms 2388 KB Output is correct
31 Correct 23 ms 3392 KB Output is correct
32 Correct 25 ms 3412 KB Output is correct
33 Correct 29 ms 3404 KB Output is correct
34 Correct 22 ms 3404 KB Output is correct
35 Correct 23 ms 3448 KB Output is correct
36 Correct 23 ms 3348 KB Output is correct
37 Correct 24 ms 3416 KB Output is correct
38 Correct 29 ms 3328 KB Output is correct
39 Correct 26 ms 3360 KB Output is correct
40 Correct 24 ms 3432 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 6 ms 872 KB Output is correct
48 Correct 6 ms 872 KB Output is correct
49 Correct 14 ms 1512 KB Output is correct
50 Correct 32 ms 2644 KB Output is correct
51 Correct 38 ms 3788 KB Output is correct
52 Correct 37 ms 3880 KB Output is correct
53 Correct 36 ms 3856 KB Output is correct
54 Correct 36 ms 3868 KB Output is correct
55 Correct 37 ms 3872 KB Output is correct
56 Correct 35 ms 3804 KB Output is correct
57 Correct 35 ms 3792 KB Output is correct
58 Correct 48 ms 3860 KB Output is correct
59 Correct 46 ms 3864 KB Output is correct
60 Correct 41 ms 3800 KB Output is correct
61 Correct 36 ms 3792 KB Output is correct
62 Correct 40 ms 3872 KB Output is correct
63 Correct 37 ms 3864 KB Output is correct
64 Correct 36 ms 3796 KB Output is correct
65 Correct 36 ms 3792 KB Output is correct
66 Correct 35 ms 3880 KB Output is correct
67 Correct 42 ms 3820 KB Output is correct
68 Correct 39 ms 3864 KB Output is correct
69 Correct 39 ms 3784 KB Output is correct
70 Correct 38 ms 3800 KB Output is correct
71 Correct 9 ms 1008 KB Output is correct
72 Correct 7 ms 980 KB Output is correct
73 Correct 8 ms 996 KB Output is correct
74 Correct 8 ms 1048 KB Output is correct
75 Correct 8 ms 980 KB Output is correct
76 Correct 16 ms 1876 KB Output is correct
77 Correct 16 ms 1912 KB Output is correct
78 Correct 21 ms 1868 KB Output is correct
79 Correct 18 ms 1840 KB Output is correct
80 Correct 17 ms 1888 KB Output is correct
81 Correct 37 ms 3416 KB Output is correct
82 Correct 36 ms 3448 KB Output is correct
83 Correct 37 ms 3444 KB Output is correct
84 Correct 35 ms 3424 KB Output is correct
85 Correct 36 ms 3432 KB Output is correct
86 Correct 56 ms 4140 KB Output is correct
87 Correct 54 ms 4176 KB Output is correct
88 Correct 46 ms 4232 KB Output is correct
89 Correct 45 ms 4300 KB Output is correct
90 Correct 45 ms 4256 KB Output is correct
91 Correct 109 ms 10612 KB Output is correct
92 Correct 101 ms 10648 KB Output is correct
93 Correct 105 ms 10632 KB Output is correct
94 Correct 111 ms 10684 KB Output is correct
95 Correct 114 ms 10596 KB Output is correct
96 Correct 175 ms 17040 KB Output is correct
97 Correct 171 ms 17124 KB Output is correct
98 Correct 207 ms 17076 KB Output is correct
99 Correct 150 ms 17060 KB Output is correct
100 Correct 152 ms 17040 KB Output is correct
101 Correct 178 ms 17164 KB Output is correct
102 Correct 184 ms 17088 KB Output is correct
103 Correct 147 ms 17100 KB Output is correct
104 Correct 177 ms 17084 KB Output is correct
105 Correct 168 ms 17084 KB Output is correct
106 Correct 209 ms 20280 KB Output is correct
107 Correct 198 ms 20312 KB Output is correct
108 Correct 208 ms 20344 KB Output is correct
109 Correct 184 ms 20304 KB Output is correct
110 Correct 179 ms 20292 KB Output is correct
111 Correct 238 ms 20220 KB Output is correct
112 Correct 225 ms 20320 KB Output is correct
113 Correct 176 ms 20236 KB Output is correct
114 Correct 223 ms 20276 KB Output is correct
115 Correct 180 ms 20252 KB Output is correct
116 Incorrect 2 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -