답안 #811286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811286 2023-08-07T03:48:20 Z ono_de206 Diversity (CEOI21_diversity) C++14
64 / 100
40 ms 10828 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

#define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
    return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
    return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
    return in;
}


template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 3e5 + 10;
int a[mxn], cnt[mxn];

void go() {
	int n, q;
	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	vector<pair<int, int>> v;
	for(int i = 1; i <= 300000; i++) {
		if(cnt[i] != 0) {
			v.eb(cnt[i], i);
		}
	}
	sort(all(v));
	int tp = 1, l = 1, r = n;
	for(auto it : v) {
		for(int i = 0; i < it.ff; i++) {
			if(tp) a[l++] = it.ss;
			else a[r--] = it.ss;
		}
		tp ^= 1;
	}
	// do {
	// 	int ans = n * (n + 1) / 2;
	// 	for(int i = 1; i <= n; i++) {
	// 		if(i == 1 || a[i] != a[i - 1]) {
	// 			ans += (i - 1) * (n - i + 1);
	// 		}
	// 	}	
	// 	if(ans == 148) {
	// 		for(int i = 1; i <= n; i++) {
	// 			cout << a[i] << ' ';
	// 		}
	// 		cout << '\n';
	// 	}
	// } while(next_permutation(a + 1, a + n + 1));
	int ans = n * (n + 1) / 2;
	for(int i = 1; i <= n; i++) {
		if(i == 1 || a[i] != a[i - 1]) {
			ans += (i - 1) * (n - i + 1);
		}
	}
	cout << ans << '\n';
}

signed main() {
	// #ifndef ONO
	// freopen("file.in", "r", stdin);
	// freopen("file.out", "w", stdout);
	// #endif
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 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 328 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 9 ms 2220 KB Output is correct
6 Correct 14 ms 3280 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 13 ms 3284 KB Output is correct
9 Correct 13 ms 3284 KB Output is correct
10 Correct 13 ms 3252 KB Output is correct
11 Correct 13 ms 3248 KB Output is correct
12 Correct 14 ms 3284 KB Output is correct
13 Correct 13 ms 3272 KB Output is correct
14 Correct 13 ms 3232 KB Output is correct
15 Correct 13 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 9 ms 2220 KB Output is correct
6 Correct 14 ms 3280 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 13 ms 3284 KB Output is correct
9 Correct 13 ms 3284 KB Output is correct
10 Correct 13 ms 3252 KB Output is correct
11 Correct 13 ms 3248 KB Output is correct
12 Correct 14 ms 3284 KB Output is correct
13 Correct 13 ms 3272 KB Output is correct
14 Correct 13 ms 3232 KB Output is correct
15 Correct 13 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 1 ms 340 KB Output is correct
19 Correct 5 ms 1364 KB Output is correct
20 Correct 10 ms 2388 KB Output is correct
21 Correct 15 ms 3432 KB Output is correct
22 Correct 15 ms 3416 KB Output is correct
23 Correct 22 ms 3360 KB Output is correct
24 Correct 14 ms 3412 KB Output is correct
25 Correct 15 ms 3452 KB Output is correct
26 Correct 15 ms 3412 KB Output is correct
27 Correct 14 ms 3412 KB Output is correct
28 Correct 14 ms 3316 KB Output is correct
29 Correct 18 ms 3404 KB Output is correct
30 Correct 14 ms 3392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 9 ms 2220 KB Output is correct
6 Correct 14 ms 3280 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 13 ms 3284 KB Output is correct
9 Correct 13 ms 3284 KB Output is correct
10 Correct 13 ms 3252 KB Output is correct
11 Correct 13 ms 3248 KB Output is correct
12 Correct 14 ms 3284 KB Output is correct
13 Correct 13 ms 3272 KB Output is correct
14 Correct 13 ms 3232 KB Output is correct
15 Correct 13 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 1 ms 340 KB Output is correct
19 Correct 5 ms 1364 KB Output is correct
20 Correct 10 ms 2388 KB Output is correct
21 Correct 15 ms 3432 KB Output is correct
22 Correct 15 ms 3416 KB Output is correct
23 Correct 22 ms 3360 KB Output is correct
24 Correct 14 ms 3412 KB Output is correct
25 Correct 15 ms 3452 KB Output is correct
26 Correct 15 ms 3412 KB Output is correct
27 Correct 14 ms 3412 KB Output is correct
28 Correct 14 ms 3316 KB Output is correct
29 Correct 18 ms 3404 KB Output is correct
30 Correct 14 ms 3392 KB Output is correct
31 Correct 1 ms 328 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 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 7 ms 1496 KB Output is correct
40 Correct 11 ms 2620 KB Output is correct
41 Correct 16 ms 3812 KB Output is correct
42 Correct 15 ms 3756 KB Output is correct
43 Correct 16 ms 3752 KB Output is correct
44 Correct 16 ms 3752 KB Output is correct
45 Correct 16 ms 3860 KB Output is correct
46 Correct 15 ms 3796 KB Output is correct
47 Correct 15 ms 3728 KB Output is correct
48 Correct 15 ms 3788 KB Output is correct
49 Correct 16 ms 3792 KB Output is correct
50 Correct 16 ms 3788 KB Output is correct
51 Correct 16 ms 3836 KB Output is correct
52 Correct 18 ms 3780 KB Output is correct
53 Correct 16 ms 3836 KB Output is correct
54 Correct 17 ms 3788 KB Output is correct
55 Correct 15 ms 3768 KB Output is correct
56 Correct 16 ms 3792 KB Output is correct
57 Correct 22 ms 3744 KB Output is correct
58 Correct 16 ms 3796 KB Output is correct
59 Correct 16 ms 3796 KB Output is correct
60 Correct 16 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 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 328 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 9 ms 2220 KB Output is correct
16 Correct 14 ms 3280 KB Output is correct
17 Correct 13 ms 3200 KB Output is correct
18 Correct 13 ms 3284 KB Output is correct
19 Correct 13 ms 3284 KB Output is correct
20 Correct 13 ms 3252 KB Output is correct
21 Correct 13 ms 3248 KB Output is correct
22 Correct 14 ms 3284 KB Output is correct
23 Correct 13 ms 3272 KB Output is correct
24 Correct 13 ms 3232 KB Output is correct
25 Correct 13 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 1 ms 340 KB Output is correct
29 Correct 5 ms 1364 KB Output is correct
30 Correct 10 ms 2388 KB Output is correct
31 Correct 15 ms 3432 KB Output is correct
32 Correct 15 ms 3416 KB Output is correct
33 Correct 22 ms 3360 KB Output is correct
34 Correct 14 ms 3412 KB Output is correct
35 Correct 15 ms 3452 KB Output is correct
36 Correct 15 ms 3412 KB Output is correct
37 Correct 14 ms 3412 KB Output is correct
38 Correct 14 ms 3316 KB Output is correct
39 Correct 18 ms 3404 KB Output is correct
40 Correct 14 ms 3392 KB Output is correct
41 Correct 1 ms 328 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 1 ms 340 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 3 ms 852 KB Output is correct
48 Correct 3 ms 852 KB Output is correct
49 Correct 7 ms 1496 KB Output is correct
50 Correct 11 ms 2620 KB Output is correct
51 Correct 16 ms 3812 KB Output is correct
52 Correct 15 ms 3756 KB Output is correct
53 Correct 16 ms 3752 KB Output is correct
54 Correct 16 ms 3752 KB Output is correct
55 Correct 16 ms 3860 KB Output is correct
56 Correct 15 ms 3796 KB Output is correct
57 Correct 15 ms 3728 KB Output is correct
58 Correct 15 ms 3788 KB Output is correct
59 Correct 16 ms 3792 KB Output is correct
60 Correct 16 ms 3788 KB Output is correct
61 Correct 16 ms 3836 KB Output is correct
62 Correct 18 ms 3780 KB Output is correct
63 Correct 16 ms 3836 KB Output is correct
64 Correct 17 ms 3788 KB Output is correct
65 Correct 15 ms 3768 KB Output is correct
66 Correct 16 ms 3792 KB Output is correct
67 Correct 22 ms 3744 KB Output is correct
68 Correct 16 ms 3796 KB Output is correct
69 Correct 16 ms 3796 KB Output is correct
70 Correct 16 ms 3796 KB Output is correct
71 Correct 4 ms 980 KB Output is correct
72 Correct 6 ms 980 KB Output is correct
73 Correct 4 ms 980 KB Output is correct
74 Correct 4 ms 976 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 7 ms 1776 KB Output is correct
77 Correct 7 ms 1808 KB Output is correct
78 Correct 7 ms 1748 KB Output is correct
79 Correct 7 ms 1748 KB Output is correct
80 Correct 7 ms 1748 KB Output is correct
81 Correct 13 ms 3224 KB Output is correct
82 Correct 13 ms 3284 KB Output is correct
83 Correct 13 ms 3264 KB Output is correct
84 Correct 13 ms 3284 KB Output is correct
85 Correct 12 ms 3280 KB Output is correct
86 Correct 19 ms 3772 KB Output is correct
87 Correct 15 ms 3712 KB Output is correct
88 Correct 15 ms 3672 KB Output is correct
89 Correct 20 ms 3792 KB Output is correct
90 Correct 15 ms 3788 KB Output is correct
91 Correct 30 ms 7376 KB Output is correct
92 Correct 30 ms 7308 KB Output is correct
93 Correct 29 ms 7360 KB Output is correct
94 Correct 29 ms 7368 KB Output is correct
95 Correct 33 ms 7308 KB Output is correct
96 Correct 37 ms 10364 KB Output is correct
97 Correct 40 ms 10316 KB Output is correct
98 Correct 38 ms 10320 KB Output is correct
99 Correct 38 ms 10312 KB Output is correct
100 Correct 37 ms 10360 KB Output is correct
101 Correct 37 ms 10324 KB Output is correct
102 Correct 37 ms 10380 KB Output is correct
103 Correct 39 ms 10312 KB Output is correct
104 Correct 37 ms 10360 KB Output is correct
105 Correct 37 ms 10336 KB Output is correct
106 Correct 36 ms 10828 KB Output is correct
107 Correct 37 ms 10688 KB Output is correct
108 Correct 38 ms 10692 KB Output is correct
109 Correct 38 ms 10784 KB Output is correct
110 Correct 38 ms 10728 KB Output is correct
111 Correct 38 ms 10692 KB Output is correct
112 Correct 38 ms 10788 KB Output is correct
113 Correct 39 ms 10744 KB Output is correct
114 Correct 37 ms 10692 KB Output is correct
115 Correct 40 ms 10716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 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 328 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 5 ms 1236 KB Output is correct
15 Correct 9 ms 2220 KB Output is correct
16 Correct 14 ms 3280 KB Output is correct
17 Correct 13 ms 3200 KB Output is correct
18 Correct 13 ms 3284 KB Output is correct
19 Correct 13 ms 3284 KB Output is correct
20 Correct 13 ms 3252 KB Output is correct
21 Correct 13 ms 3248 KB Output is correct
22 Correct 14 ms 3284 KB Output is correct
23 Correct 13 ms 3272 KB Output is correct
24 Correct 13 ms 3232 KB Output is correct
25 Correct 13 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 1 ms 340 KB Output is correct
29 Correct 5 ms 1364 KB Output is correct
30 Correct 10 ms 2388 KB Output is correct
31 Correct 15 ms 3432 KB Output is correct
32 Correct 15 ms 3416 KB Output is correct
33 Correct 22 ms 3360 KB Output is correct
34 Correct 14 ms 3412 KB Output is correct
35 Correct 15 ms 3452 KB Output is correct
36 Correct 15 ms 3412 KB Output is correct
37 Correct 14 ms 3412 KB Output is correct
38 Correct 14 ms 3316 KB Output is correct
39 Correct 18 ms 3404 KB Output is correct
40 Correct 14 ms 3392 KB Output is correct
41 Correct 1 ms 328 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 1 ms 340 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 3 ms 852 KB Output is correct
48 Correct 3 ms 852 KB Output is correct
49 Correct 7 ms 1496 KB Output is correct
50 Correct 11 ms 2620 KB Output is correct
51 Correct 16 ms 3812 KB Output is correct
52 Correct 15 ms 3756 KB Output is correct
53 Correct 16 ms 3752 KB Output is correct
54 Correct 16 ms 3752 KB Output is correct
55 Correct 16 ms 3860 KB Output is correct
56 Correct 15 ms 3796 KB Output is correct
57 Correct 15 ms 3728 KB Output is correct
58 Correct 15 ms 3788 KB Output is correct
59 Correct 16 ms 3792 KB Output is correct
60 Correct 16 ms 3788 KB Output is correct
61 Correct 16 ms 3836 KB Output is correct
62 Correct 18 ms 3780 KB Output is correct
63 Correct 16 ms 3836 KB Output is correct
64 Correct 17 ms 3788 KB Output is correct
65 Correct 15 ms 3768 KB Output is correct
66 Correct 16 ms 3792 KB Output is correct
67 Correct 22 ms 3744 KB Output is correct
68 Correct 16 ms 3796 KB Output is correct
69 Correct 16 ms 3796 KB Output is correct
70 Correct 16 ms 3796 KB Output is correct
71 Correct 4 ms 980 KB Output is correct
72 Correct 6 ms 980 KB Output is correct
73 Correct 4 ms 980 KB Output is correct
74 Correct 4 ms 976 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 7 ms 1776 KB Output is correct
77 Correct 7 ms 1808 KB Output is correct
78 Correct 7 ms 1748 KB Output is correct
79 Correct 7 ms 1748 KB Output is correct
80 Correct 7 ms 1748 KB Output is correct
81 Correct 13 ms 3224 KB Output is correct
82 Correct 13 ms 3284 KB Output is correct
83 Correct 13 ms 3264 KB Output is correct
84 Correct 13 ms 3284 KB Output is correct
85 Correct 12 ms 3280 KB Output is correct
86 Correct 19 ms 3772 KB Output is correct
87 Correct 15 ms 3712 KB Output is correct
88 Correct 15 ms 3672 KB Output is correct
89 Correct 20 ms 3792 KB Output is correct
90 Correct 15 ms 3788 KB Output is correct
91 Correct 30 ms 7376 KB Output is correct
92 Correct 30 ms 7308 KB Output is correct
93 Correct 29 ms 7360 KB Output is correct
94 Correct 29 ms 7368 KB Output is correct
95 Correct 33 ms 7308 KB Output is correct
96 Correct 37 ms 10364 KB Output is correct
97 Correct 40 ms 10316 KB Output is correct
98 Correct 38 ms 10320 KB Output is correct
99 Correct 38 ms 10312 KB Output is correct
100 Correct 37 ms 10360 KB Output is correct
101 Correct 37 ms 10324 KB Output is correct
102 Correct 37 ms 10380 KB Output is correct
103 Correct 39 ms 10312 KB Output is correct
104 Correct 37 ms 10360 KB Output is correct
105 Correct 37 ms 10336 KB Output is correct
106 Correct 36 ms 10828 KB Output is correct
107 Correct 37 ms 10688 KB Output is correct
108 Correct 38 ms 10692 KB Output is correct
109 Correct 38 ms 10784 KB Output is correct
110 Correct 38 ms 10728 KB Output is correct
111 Correct 38 ms 10692 KB Output is correct
112 Correct 38 ms 10788 KB Output is correct
113 Correct 39 ms 10744 KB Output is correct
114 Correct 37 ms 10692 KB Output is correct
115 Correct 40 ms 10716 KB Output is correct
116 Incorrect 1 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -