Submission #894850

# Submission time Handle Problem Language Result Execution time Memory
894850 2023-12-29T05:54:17 Z vjudge1 Diversity (CEOI21_diversity) C++11
64 / 100
58 ms 7904 KB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 3 * 1e5 + 10;
const ll mod = 1e9 + 7;

ll um(ll a, ll b){
	return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll add(ll a, ll b){
	return (1LL * a + b) % mod;
}
ll binpow(ll x, ll step){
	ll res = 1LL;
	while(step){
		if(step & 1) res = um(res, x);
		x = um(x, x);
		step /= 2;
	}
	return res;
}
int arr[N];
pii place[N];
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	ll n, q, cnt = 0;
  	cin >> n >> q;
  	for(ll i = 1; i <= n; i++){
  		cin >> arr[i];
  	}
  	sort(arr + 1, arr + n + 1);
  	vector <pii> vec;
  	for(ll i = 1; i <= n; i++){
  		if(arr[i] != arr[i - 1]){
  			if(cnt > 0) vec.pb({cnt, arr[i - 1]});
  			cnt = 1;
  		} else cnt++;
  	}
  	vec.pb({cnt, arr[n]});
  	sort(vec.begin(), vec.end());
  	int l = 0, r = (int)vec.size() - 1;
  	for(int i = 0; i < (int)vec.size(); i++){
  		if(i % 2 == 0) place[l++] = vec[i];
  		else place[r--] = vec[i];
  	}
  	l = 1;
  	for(int i = 0; i < (int)vec.size(); i++){
  		for(int j = 0; j < place[i].F; j++){
  			arr[l++] = place[i].S;
  		}
  	}
  	
  	ll ans = 0, cur = 0;
  	cnt = 0;
  	for(ll i = 1; i <= n; i++){
  		if(arr[i] != arr[i - 1]) cnt++;
  		cur += cnt;
  	}
  	for(ll i = 1; i <= n; i++){
  		ans += cur;
  		cur--;
  		if(arr[i] != arr[i + 1]) cur -= (n - i);
  	}
  	cout << ans;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 6 ms 860 KB Output is correct
5 Correct 12 ms 1628 KB Output is correct
6 Correct 20 ms 2108 KB Output is correct
7 Correct 18 ms 2140 KB Output is correct
8 Correct 19 ms 2060 KB Output is correct
9 Correct 19 ms 2140 KB Output is correct
10 Correct 19 ms 2136 KB Output is correct
11 Correct 19 ms 2136 KB Output is correct
12 Correct 20 ms 2300 KB Output is correct
13 Correct 20 ms 2140 KB Output is correct
14 Correct 19 ms 2136 KB Output is correct
15 Correct 19 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 6 ms 860 KB Output is correct
5 Correct 12 ms 1628 KB Output is correct
6 Correct 20 ms 2108 KB Output is correct
7 Correct 18 ms 2140 KB Output is correct
8 Correct 19 ms 2060 KB Output is correct
9 Correct 19 ms 2140 KB Output is correct
10 Correct 19 ms 2136 KB Output is correct
11 Correct 19 ms 2136 KB Output is correct
12 Correct 20 ms 2300 KB Output is correct
13 Correct 20 ms 2140 KB Output is correct
14 Correct 19 ms 2136 KB Output is correct
15 Correct 19 ms 2136 KB Output is correct
16 Correct 0 ms 344 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 1128 KB Output is correct
20 Correct 15 ms 1720 KB Output is correct
21 Correct 21 ms 2396 KB Output is correct
22 Correct 22 ms 2396 KB Output is correct
23 Correct 25 ms 2908 KB Output is correct
24 Correct 22 ms 2408 KB Output is correct
25 Correct 21 ms 2424 KB Output is correct
26 Correct 23 ms 2156 KB Output is correct
27 Correct 22 ms 2400 KB Output is correct
28 Correct 21 ms 2140 KB Output is correct
29 Correct 21 ms 2140 KB Output is correct
30 Correct 22 ms 2408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 6 ms 860 KB Output is correct
5 Correct 12 ms 1628 KB Output is correct
6 Correct 20 ms 2108 KB Output is correct
7 Correct 18 ms 2140 KB Output is correct
8 Correct 19 ms 2060 KB Output is correct
9 Correct 19 ms 2140 KB Output is correct
10 Correct 19 ms 2136 KB Output is correct
11 Correct 19 ms 2136 KB Output is correct
12 Correct 20 ms 2300 KB Output is correct
13 Correct 20 ms 2140 KB Output is correct
14 Correct 19 ms 2136 KB Output is correct
15 Correct 19 ms 2136 KB Output is correct
16 Correct 0 ms 344 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 1128 KB Output is correct
20 Correct 15 ms 1720 KB Output is correct
21 Correct 21 ms 2396 KB Output is correct
22 Correct 22 ms 2396 KB Output is correct
23 Correct 25 ms 2908 KB Output is correct
24 Correct 22 ms 2408 KB Output is correct
25 Correct 21 ms 2424 KB Output is correct
26 Correct 23 ms 2156 KB Output is correct
27 Correct 22 ms 2400 KB Output is correct
28 Correct 21 ms 2140 KB Output is correct
29 Correct 21 ms 2140 KB Output is correct
30 Correct 22 ms 2408 KB Output is correct
31 Correct 0 ms 360 KB Output is correct
32 Correct 1 ms 348 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 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 5 ms 768 KB Output is correct
38 Correct 5 ms 856 KB Output is correct
39 Correct 10 ms 1116 KB Output is correct
40 Correct 19 ms 2004 KB Output is correct
41 Correct 28 ms 2776 KB Output is correct
42 Correct 28 ms 2640 KB Output is correct
43 Correct 34 ms 3072 KB Output is correct
44 Correct 28 ms 2648 KB Output is correct
45 Correct 28 ms 2652 KB Output is correct
46 Correct 28 ms 2652 KB Output is correct
47 Correct 27 ms 2556 KB Output is correct
48 Correct 28 ms 2768 KB Output is correct
49 Correct 28 ms 2652 KB Output is correct
50 Correct 28 ms 2652 KB Output is correct
51 Correct 28 ms 2648 KB Output is correct
52 Correct 28 ms 2648 KB Output is correct
53 Correct 28 ms 2652 KB Output is correct
54 Correct 28 ms 2652 KB Output is correct
55 Correct 28 ms 2760 KB Output is correct
56 Correct 28 ms 2648 KB Output is correct
57 Correct 30 ms 2652 KB Output is correct
58 Correct 27 ms 2640 KB Output is correct
59 Correct 33 ms 2816 KB Output is correct
60 Correct 28 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 6 ms 860 KB Output is correct
15 Correct 12 ms 1628 KB Output is correct
16 Correct 20 ms 2108 KB Output is correct
17 Correct 18 ms 2140 KB Output is correct
18 Correct 19 ms 2060 KB Output is correct
19 Correct 19 ms 2140 KB Output is correct
20 Correct 19 ms 2136 KB Output is correct
21 Correct 19 ms 2136 KB Output is correct
22 Correct 20 ms 2300 KB Output is correct
23 Correct 20 ms 2140 KB Output is correct
24 Correct 19 ms 2136 KB Output is correct
25 Correct 19 ms 2136 KB Output is correct
26 Correct 0 ms 344 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 1128 KB Output is correct
30 Correct 15 ms 1720 KB Output is correct
31 Correct 21 ms 2396 KB Output is correct
32 Correct 22 ms 2396 KB Output is correct
33 Correct 25 ms 2908 KB Output is correct
34 Correct 22 ms 2408 KB Output is correct
35 Correct 21 ms 2424 KB Output is correct
36 Correct 23 ms 2156 KB Output is correct
37 Correct 22 ms 2400 KB Output is correct
38 Correct 21 ms 2140 KB Output is correct
39 Correct 21 ms 2140 KB Output is correct
40 Correct 22 ms 2408 KB Output is correct
41 Correct 0 ms 360 KB Output is correct
42 Correct 1 ms 348 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 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 5 ms 768 KB Output is correct
48 Correct 5 ms 856 KB Output is correct
49 Correct 10 ms 1116 KB Output is correct
50 Correct 19 ms 2004 KB Output is correct
51 Correct 28 ms 2776 KB Output is correct
52 Correct 28 ms 2640 KB Output is correct
53 Correct 34 ms 3072 KB Output is correct
54 Correct 28 ms 2648 KB Output is correct
55 Correct 28 ms 2652 KB Output is correct
56 Correct 28 ms 2652 KB Output is correct
57 Correct 27 ms 2556 KB Output is correct
58 Correct 28 ms 2768 KB Output is correct
59 Correct 28 ms 2652 KB Output is correct
60 Correct 28 ms 2652 KB Output is correct
61 Correct 28 ms 2648 KB Output is correct
62 Correct 28 ms 2648 KB Output is correct
63 Correct 28 ms 2652 KB Output is correct
64 Correct 28 ms 2652 KB Output is correct
65 Correct 28 ms 2760 KB Output is correct
66 Correct 28 ms 2648 KB Output is correct
67 Correct 30 ms 2652 KB Output is correct
68 Correct 27 ms 2640 KB Output is correct
69 Correct 33 ms 2816 KB Output is correct
70 Correct 28 ms 2648 KB Output is correct
71 Correct 6 ms 860 KB Output is correct
72 Correct 7 ms 860 KB Output is correct
73 Correct 6 ms 880 KB Output is correct
74 Correct 5 ms 860 KB Output is correct
75 Correct 6 ms 860 KB Output is correct
76 Correct 11 ms 1324 KB Output is correct
77 Correct 11 ms 1372 KB Output is correct
78 Correct 11 ms 1368 KB Output is correct
79 Correct 11 ms 1372 KB Output is correct
80 Correct 11 ms 1376 KB Output is correct
81 Correct 23 ms 2400 KB Output is correct
82 Correct 23 ms 2284 KB Output is correct
83 Correct 23 ms 2400 KB Output is correct
84 Correct 23 ms 2444 KB Output is correct
85 Correct 23 ms 2396 KB Output is correct
86 Correct 26 ms 2636 KB Output is correct
87 Correct 26 ms 2652 KB Output is correct
88 Correct 27 ms 2656 KB Output is correct
89 Correct 26 ms 2652 KB Output is correct
90 Correct 26 ms 2688 KB Output is correct
91 Correct 54 ms 6296 KB Output is correct
92 Correct 46 ms 6352 KB Output is correct
93 Correct 47 ms 6352 KB Output is correct
94 Correct 46 ms 6348 KB Output is correct
95 Correct 47 ms 6280 KB Output is correct
96 Correct 55 ms 7372 KB Output is correct
97 Correct 55 ms 7372 KB Output is correct
98 Correct 56 ms 7372 KB Output is correct
99 Correct 55 ms 7224 KB Output is correct
100 Correct 55 ms 7228 KB Output is correct
101 Correct 54 ms 7368 KB Output is correct
102 Correct 55 ms 7368 KB Output is correct
103 Correct 56 ms 7372 KB Output is correct
104 Correct 54 ms 7208 KB Output is correct
105 Correct 54 ms 7368 KB Output is correct
106 Correct 57 ms 7904 KB Output is correct
107 Correct 58 ms 7628 KB Output is correct
108 Correct 54 ms 7624 KB Output is correct
109 Correct 54 ms 7624 KB Output is correct
110 Correct 55 ms 7704 KB Output is correct
111 Correct 55 ms 7624 KB Output is correct
112 Correct 55 ms 7696 KB Output is correct
113 Correct 55 ms 7700 KB Output is correct
114 Correct 54 ms 7628 KB Output is correct
115 Correct 57 ms 7628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 464 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 6 ms 860 KB Output is correct
15 Correct 12 ms 1628 KB Output is correct
16 Correct 20 ms 2108 KB Output is correct
17 Correct 18 ms 2140 KB Output is correct
18 Correct 19 ms 2060 KB Output is correct
19 Correct 19 ms 2140 KB Output is correct
20 Correct 19 ms 2136 KB Output is correct
21 Correct 19 ms 2136 KB Output is correct
22 Correct 20 ms 2300 KB Output is correct
23 Correct 20 ms 2140 KB Output is correct
24 Correct 19 ms 2136 KB Output is correct
25 Correct 19 ms 2136 KB Output is correct
26 Correct 0 ms 344 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 1128 KB Output is correct
30 Correct 15 ms 1720 KB Output is correct
31 Correct 21 ms 2396 KB Output is correct
32 Correct 22 ms 2396 KB Output is correct
33 Correct 25 ms 2908 KB Output is correct
34 Correct 22 ms 2408 KB Output is correct
35 Correct 21 ms 2424 KB Output is correct
36 Correct 23 ms 2156 KB Output is correct
37 Correct 22 ms 2400 KB Output is correct
38 Correct 21 ms 2140 KB Output is correct
39 Correct 21 ms 2140 KB Output is correct
40 Correct 22 ms 2408 KB Output is correct
41 Correct 0 ms 360 KB Output is correct
42 Correct 1 ms 348 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 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 5 ms 768 KB Output is correct
48 Correct 5 ms 856 KB Output is correct
49 Correct 10 ms 1116 KB Output is correct
50 Correct 19 ms 2004 KB Output is correct
51 Correct 28 ms 2776 KB Output is correct
52 Correct 28 ms 2640 KB Output is correct
53 Correct 34 ms 3072 KB Output is correct
54 Correct 28 ms 2648 KB Output is correct
55 Correct 28 ms 2652 KB Output is correct
56 Correct 28 ms 2652 KB Output is correct
57 Correct 27 ms 2556 KB Output is correct
58 Correct 28 ms 2768 KB Output is correct
59 Correct 28 ms 2652 KB Output is correct
60 Correct 28 ms 2652 KB Output is correct
61 Correct 28 ms 2648 KB Output is correct
62 Correct 28 ms 2648 KB Output is correct
63 Correct 28 ms 2652 KB Output is correct
64 Correct 28 ms 2652 KB Output is correct
65 Correct 28 ms 2760 KB Output is correct
66 Correct 28 ms 2648 KB Output is correct
67 Correct 30 ms 2652 KB Output is correct
68 Correct 27 ms 2640 KB Output is correct
69 Correct 33 ms 2816 KB Output is correct
70 Correct 28 ms 2648 KB Output is correct
71 Correct 6 ms 860 KB Output is correct
72 Correct 7 ms 860 KB Output is correct
73 Correct 6 ms 880 KB Output is correct
74 Correct 5 ms 860 KB Output is correct
75 Correct 6 ms 860 KB Output is correct
76 Correct 11 ms 1324 KB Output is correct
77 Correct 11 ms 1372 KB Output is correct
78 Correct 11 ms 1368 KB Output is correct
79 Correct 11 ms 1372 KB Output is correct
80 Correct 11 ms 1376 KB Output is correct
81 Correct 23 ms 2400 KB Output is correct
82 Correct 23 ms 2284 KB Output is correct
83 Correct 23 ms 2400 KB Output is correct
84 Correct 23 ms 2444 KB Output is correct
85 Correct 23 ms 2396 KB Output is correct
86 Correct 26 ms 2636 KB Output is correct
87 Correct 26 ms 2652 KB Output is correct
88 Correct 27 ms 2656 KB Output is correct
89 Correct 26 ms 2652 KB Output is correct
90 Correct 26 ms 2688 KB Output is correct
91 Correct 54 ms 6296 KB Output is correct
92 Correct 46 ms 6352 KB Output is correct
93 Correct 47 ms 6352 KB Output is correct
94 Correct 46 ms 6348 KB Output is correct
95 Correct 47 ms 6280 KB Output is correct
96 Correct 55 ms 7372 KB Output is correct
97 Correct 55 ms 7372 KB Output is correct
98 Correct 56 ms 7372 KB Output is correct
99 Correct 55 ms 7224 KB Output is correct
100 Correct 55 ms 7228 KB Output is correct
101 Correct 54 ms 7368 KB Output is correct
102 Correct 55 ms 7368 KB Output is correct
103 Correct 56 ms 7372 KB Output is correct
104 Correct 54 ms 7208 KB Output is correct
105 Correct 54 ms 7368 KB Output is correct
106 Correct 57 ms 7904 KB Output is correct
107 Correct 58 ms 7628 KB Output is correct
108 Correct 54 ms 7624 KB Output is correct
109 Correct 54 ms 7624 KB Output is correct
110 Correct 55 ms 7704 KB Output is correct
111 Correct 55 ms 7624 KB Output is correct
112 Correct 55 ms 7696 KB Output is correct
113 Correct 55 ms 7700 KB Output is correct
114 Correct 54 ms 7628 KB Output is correct
115 Correct 57 ms 7628 KB Output is correct
116 Incorrect 2 ms 600 KB Output isn't correct
117 Halted 0 ms 0 KB -