답안 #479151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479151 2021-10-10T08:06:53 Z errorgorn Diversity (CEOI21_diversity) C++17
64 / 100
111 ms 21412 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

ll qexp(ll b,ll p,int m){
    ll res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}

ll inv(ll i){
	return qexp(i,MOD-2,MOD);
}

ll fix(ll i){
	i%=MOD;
	if (i<0) i+=MOD;
	return i;
}

ll fac[1000005];
ll ifac[1000005];

ll nCk(int i,int j){
	if (i<j) return 0;
	return fac[i]*ifac[j]%MOD*ifac[i-j]%MOD;
}

int n,q;
int arr[300005];
int cnt[300005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	fac[0]=1;
	rep(x,1,1000005) fac[x]=fac[x-1]*x%MOD;
	ifac[1000004]=inv(fac[1000004]);
	rep(x,1000005,1) ifac[x-1]=ifac[x]*x%MOD;
	
	cin>>n>>q;
	rep(x,1,n+1) cin>>arr[x];
	rep(x,1,n+1) cnt[arr[x]]++;
	
	vector<int> v;
	rep(x,1,300005) v.pub(x);
	sort(all(v),[](int i,int j){
		if (cnt[i]!=cnt[j]) return cnt[i]>cnt[j];
		else return i<j;
	});
	
	rep(x,0,sz(v)){
		if (x%2==0) cnt[v[x]]=x/2;
		else cnt[v[x]]=-(x+1)/2;
	}
	//rep(x,1,10) cout<<cnt[x]<<" "; cout<<endl;
	
	sort(arr+1,arr+n+1,[](int i,int j){
		if (cnt[i]!=cnt[j]) return cnt[i]<cnt[j];
		else return i<j;
	});
	
	//rep(x,1,n+1) cout<<arr[x]<<" "; cout<<endl;
	
	ll ans=0;
	ll cnt=0;
	rep(x,1,n+1){
		if (arr[x-1]!=arr[x]) cnt+=x;
		else cnt++;
		ans+=cnt;
	}
	
	cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 30 ms 18444 KB Output is correct
3 Correct 29 ms 18396 KB Output is correct
4 Correct 28 ms 18360 KB Output is correct
5 Correct 31 ms 18444 KB Output is correct
6 Correct 28 ms 18452 KB Output is correct
7 Correct 30 ms 18396 KB Output is correct
8 Correct 35 ms 18392 KB Output is correct
9 Correct 34 ms 18364 KB Output is correct
10 Correct 29 ms 18336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 31 ms 18348 KB Output is correct
3 Correct 32 ms 18516 KB Output is correct
4 Correct 39 ms 18920 KB Output is correct
5 Correct 60 ms 19628 KB Output is correct
6 Correct 75 ms 20284 KB Output is correct
7 Correct 64 ms 20148 KB Output is correct
8 Correct 67 ms 20176 KB Output is correct
9 Correct 70 ms 20188 KB Output is correct
10 Correct 70 ms 20268 KB Output is correct
11 Correct 68 ms 20208 KB Output is correct
12 Correct 66 ms 20188 KB Output is correct
13 Correct 75 ms 20192 KB Output is correct
14 Correct 65 ms 20256 KB Output is correct
15 Correct 64 ms 20224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 31 ms 18348 KB Output is correct
3 Correct 32 ms 18516 KB Output is correct
4 Correct 39 ms 18920 KB Output is correct
5 Correct 60 ms 19628 KB Output is correct
6 Correct 75 ms 20284 KB Output is correct
7 Correct 64 ms 20148 KB Output is correct
8 Correct 67 ms 20176 KB Output is correct
9 Correct 70 ms 20188 KB Output is correct
10 Correct 70 ms 20268 KB Output is correct
11 Correct 68 ms 20208 KB Output is correct
12 Correct 66 ms 20188 KB Output is correct
13 Correct 75 ms 20192 KB Output is correct
14 Correct 65 ms 20256 KB Output is correct
15 Correct 64 ms 20224 KB Output is correct
16 Correct 27 ms 18364 KB Output is correct
17 Correct 28 ms 18476 KB Output is correct
18 Correct 34 ms 18512 KB Output is correct
19 Correct 44 ms 19104 KB Output is correct
20 Correct 55 ms 19652 KB Output is correct
21 Correct 68 ms 20416 KB Output is correct
22 Correct 75 ms 20312 KB Output is correct
23 Correct 65 ms 20368 KB Output is correct
24 Correct 69 ms 20368 KB Output is correct
25 Correct 71 ms 20288 KB Output is correct
26 Correct 70 ms 20268 KB Output is correct
27 Correct 63 ms 20388 KB Output is correct
28 Correct 89 ms 20396 KB Output is correct
29 Correct 67 ms 20284 KB Output is correct
30 Correct 66 ms 20328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 31 ms 18348 KB Output is correct
3 Correct 32 ms 18516 KB Output is correct
4 Correct 39 ms 18920 KB Output is correct
5 Correct 60 ms 19628 KB Output is correct
6 Correct 75 ms 20284 KB Output is correct
7 Correct 64 ms 20148 KB Output is correct
8 Correct 67 ms 20176 KB Output is correct
9 Correct 70 ms 20188 KB Output is correct
10 Correct 70 ms 20268 KB Output is correct
11 Correct 68 ms 20208 KB Output is correct
12 Correct 66 ms 20188 KB Output is correct
13 Correct 75 ms 20192 KB Output is correct
14 Correct 65 ms 20256 KB Output is correct
15 Correct 64 ms 20224 KB Output is correct
16 Correct 27 ms 18364 KB Output is correct
17 Correct 28 ms 18476 KB Output is correct
18 Correct 34 ms 18512 KB Output is correct
19 Correct 44 ms 19104 KB Output is correct
20 Correct 55 ms 19652 KB Output is correct
21 Correct 68 ms 20416 KB Output is correct
22 Correct 75 ms 20312 KB Output is correct
23 Correct 65 ms 20368 KB Output is correct
24 Correct 69 ms 20368 KB Output is correct
25 Correct 71 ms 20288 KB Output is correct
26 Correct 70 ms 20268 KB Output is correct
27 Correct 63 ms 20388 KB Output is correct
28 Correct 89 ms 20396 KB Output is correct
29 Correct 67 ms 20284 KB Output is correct
30 Correct 66 ms 20328 KB Output is correct
31 Correct 30 ms 18384 KB Output is correct
32 Correct 31 ms 18452 KB Output is correct
33 Correct 28 ms 18440 KB Output is correct
34 Correct 29 ms 18456 KB Output is correct
35 Correct 31 ms 18452 KB Output is correct
36 Correct 39 ms 18476 KB Output is correct
37 Correct 35 ms 18748 KB Output is correct
38 Correct 37 ms 18748 KB Output is correct
39 Correct 42 ms 19132 KB Output is correct
40 Correct 66 ms 19900 KB Output is correct
41 Correct 74 ms 20680 KB Output is correct
42 Correct 77 ms 20764 KB Output is correct
43 Correct 79 ms 20612 KB Output is correct
44 Correct 76 ms 20668 KB Output is correct
45 Correct 79 ms 20700 KB Output is correct
46 Correct 76 ms 20680 KB Output is correct
47 Correct 78 ms 20660 KB Output is correct
48 Correct 73 ms 20668 KB Output is correct
49 Correct 83 ms 20768 KB Output is correct
50 Correct 77 ms 20692 KB Output is correct
51 Correct 80 ms 20700 KB Output is correct
52 Correct 78 ms 20712 KB Output is correct
53 Correct 73 ms 20696 KB Output is correct
54 Correct 79 ms 20656 KB Output is correct
55 Correct 72 ms 20668 KB Output is correct
56 Correct 76 ms 20668 KB Output is correct
57 Correct 81 ms 20580 KB Output is correct
58 Correct 83 ms 20732 KB Output is correct
59 Correct 77 ms 20668 KB Output is correct
60 Correct 77 ms 20668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 30 ms 18444 KB Output is correct
3 Correct 29 ms 18396 KB Output is correct
4 Correct 28 ms 18360 KB Output is correct
5 Correct 31 ms 18444 KB Output is correct
6 Correct 28 ms 18452 KB Output is correct
7 Correct 30 ms 18396 KB Output is correct
8 Correct 35 ms 18392 KB Output is correct
9 Correct 34 ms 18364 KB Output is correct
10 Correct 29 ms 18336 KB Output is correct
11 Correct 28 ms 18440 KB Output is correct
12 Correct 31 ms 18348 KB Output is correct
13 Correct 32 ms 18516 KB Output is correct
14 Correct 39 ms 18920 KB Output is correct
15 Correct 60 ms 19628 KB Output is correct
16 Correct 75 ms 20284 KB Output is correct
17 Correct 64 ms 20148 KB Output is correct
18 Correct 67 ms 20176 KB Output is correct
19 Correct 70 ms 20188 KB Output is correct
20 Correct 70 ms 20268 KB Output is correct
21 Correct 68 ms 20208 KB Output is correct
22 Correct 66 ms 20188 KB Output is correct
23 Correct 75 ms 20192 KB Output is correct
24 Correct 65 ms 20256 KB Output is correct
25 Correct 64 ms 20224 KB Output is correct
26 Correct 27 ms 18364 KB Output is correct
27 Correct 28 ms 18476 KB Output is correct
28 Correct 34 ms 18512 KB Output is correct
29 Correct 44 ms 19104 KB Output is correct
30 Correct 55 ms 19652 KB Output is correct
31 Correct 68 ms 20416 KB Output is correct
32 Correct 75 ms 20312 KB Output is correct
33 Correct 65 ms 20368 KB Output is correct
34 Correct 69 ms 20368 KB Output is correct
35 Correct 71 ms 20288 KB Output is correct
36 Correct 70 ms 20268 KB Output is correct
37 Correct 63 ms 20388 KB Output is correct
38 Correct 89 ms 20396 KB Output is correct
39 Correct 67 ms 20284 KB Output is correct
40 Correct 66 ms 20328 KB Output is correct
41 Correct 30 ms 18384 KB Output is correct
42 Correct 31 ms 18452 KB Output is correct
43 Correct 28 ms 18440 KB Output is correct
44 Correct 29 ms 18456 KB Output is correct
45 Correct 31 ms 18452 KB Output is correct
46 Correct 39 ms 18476 KB Output is correct
47 Correct 35 ms 18748 KB Output is correct
48 Correct 37 ms 18748 KB Output is correct
49 Correct 42 ms 19132 KB Output is correct
50 Correct 66 ms 19900 KB Output is correct
51 Correct 74 ms 20680 KB Output is correct
52 Correct 77 ms 20764 KB Output is correct
53 Correct 79 ms 20612 KB Output is correct
54 Correct 76 ms 20668 KB Output is correct
55 Correct 79 ms 20700 KB Output is correct
56 Correct 76 ms 20680 KB Output is correct
57 Correct 78 ms 20660 KB Output is correct
58 Correct 73 ms 20668 KB Output is correct
59 Correct 83 ms 20768 KB Output is correct
60 Correct 77 ms 20692 KB Output is correct
61 Correct 80 ms 20700 KB Output is correct
62 Correct 78 ms 20712 KB Output is correct
63 Correct 73 ms 20696 KB Output is correct
64 Correct 79 ms 20656 KB Output is correct
65 Correct 72 ms 20668 KB Output is correct
66 Correct 76 ms 20668 KB Output is correct
67 Correct 81 ms 20580 KB Output is correct
68 Correct 83 ms 20732 KB Output is correct
69 Correct 77 ms 20668 KB Output is correct
70 Correct 77 ms 20668 KB Output is correct
71 Correct 42 ms 18820 KB Output is correct
72 Correct 36 ms 18872 KB Output is correct
73 Correct 39 ms 18764 KB Output is correct
74 Correct 41 ms 18812 KB Output is correct
75 Correct 37 ms 18876 KB Output is correct
76 Correct 48 ms 19260 KB Output is correct
77 Correct 45 ms 19260 KB Output is correct
78 Correct 46 ms 19300 KB Output is correct
79 Correct 55 ms 19256 KB Output is correct
80 Correct 46 ms 19196 KB Output is correct
81 Correct 66 ms 20156 KB Output is correct
82 Correct 67 ms 20168 KB Output is correct
83 Correct 65 ms 20160 KB Output is correct
84 Correct 64 ms 20180 KB Output is correct
85 Correct 65 ms 20168 KB Output is correct
86 Correct 75 ms 20212 KB Output is correct
87 Correct 66 ms 20156 KB Output is correct
88 Correct 74 ms 20192 KB Output is correct
89 Correct 72 ms 20424 KB Output is correct
90 Correct 67 ms 20156 KB Output is correct
91 Correct 97 ms 20804 KB Output is correct
92 Correct 98 ms 20724 KB Output is correct
93 Correct 97 ms 20800 KB Output is correct
94 Correct 99 ms 20792 KB Output is correct
95 Correct 99 ms 20712 KB Output is correct
96 Correct 110 ms 21096 KB Output is correct
97 Correct 106 ms 21184 KB Output is correct
98 Correct 109 ms 21192 KB Output is correct
99 Correct 106 ms 21184 KB Output is correct
100 Correct 101 ms 21140 KB Output is correct
101 Correct 102 ms 21184 KB Output is correct
102 Correct 107 ms 21184 KB Output is correct
103 Correct 102 ms 21184 KB Output is correct
104 Correct 102 ms 21092 KB Output is correct
105 Correct 103 ms 21080 KB Output is correct
106 Correct 105 ms 21352 KB Output is correct
107 Correct 103 ms 21412 KB Output is correct
108 Correct 107 ms 21312 KB Output is correct
109 Correct 103 ms 21312 KB Output is correct
110 Correct 104 ms 21300 KB Output is correct
111 Correct 106 ms 21388 KB Output is correct
112 Correct 106 ms 21312 KB Output is correct
113 Correct 107 ms 21304 KB Output is correct
114 Correct 111 ms 21312 KB Output is correct
115 Correct 106 ms 21312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18440 KB Output is correct
2 Correct 30 ms 18444 KB Output is correct
3 Correct 29 ms 18396 KB Output is correct
4 Correct 28 ms 18360 KB Output is correct
5 Correct 31 ms 18444 KB Output is correct
6 Correct 28 ms 18452 KB Output is correct
7 Correct 30 ms 18396 KB Output is correct
8 Correct 35 ms 18392 KB Output is correct
9 Correct 34 ms 18364 KB Output is correct
10 Correct 29 ms 18336 KB Output is correct
11 Correct 28 ms 18440 KB Output is correct
12 Correct 31 ms 18348 KB Output is correct
13 Correct 32 ms 18516 KB Output is correct
14 Correct 39 ms 18920 KB Output is correct
15 Correct 60 ms 19628 KB Output is correct
16 Correct 75 ms 20284 KB Output is correct
17 Correct 64 ms 20148 KB Output is correct
18 Correct 67 ms 20176 KB Output is correct
19 Correct 70 ms 20188 KB Output is correct
20 Correct 70 ms 20268 KB Output is correct
21 Correct 68 ms 20208 KB Output is correct
22 Correct 66 ms 20188 KB Output is correct
23 Correct 75 ms 20192 KB Output is correct
24 Correct 65 ms 20256 KB Output is correct
25 Correct 64 ms 20224 KB Output is correct
26 Correct 27 ms 18364 KB Output is correct
27 Correct 28 ms 18476 KB Output is correct
28 Correct 34 ms 18512 KB Output is correct
29 Correct 44 ms 19104 KB Output is correct
30 Correct 55 ms 19652 KB Output is correct
31 Correct 68 ms 20416 KB Output is correct
32 Correct 75 ms 20312 KB Output is correct
33 Correct 65 ms 20368 KB Output is correct
34 Correct 69 ms 20368 KB Output is correct
35 Correct 71 ms 20288 KB Output is correct
36 Correct 70 ms 20268 KB Output is correct
37 Correct 63 ms 20388 KB Output is correct
38 Correct 89 ms 20396 KB Output is correct
39 Correct 67 ms 20284 KB Output is correct
40 Correct 66 ms 20328 KB Output is correct
41 Correct 30 ms 18384 KB Output is correct
42 Correct 31 ms 18452 KB Output is correct
43 Correct 28 ms 18440 KB Output is correct
44 Correct 29 ms 18456 KB Output is correct
45 Correct 31 ms 18452 KB Output is correct
46 Correct 39 ms 18476 KB Output is correct
47 Correct 35 ms 18748 KB Output is correct
48 Correct 37 ms 18748 KB Output is correct
49 Correct 42 ms 19132 KB Output is correct
50 Correct 66 ms 19900 KB Output is correct
51 Correct 74 ms 20680 KB Output is correct
52 Correct 77 ms 20764 KB Output is correct
53 Correct 79 ms 20612 KB Output is correct
54 Correct 76 ms 20668 KB Output is correct
55 Correct 79 ms 20700 KB Output is correct
56 Correct 76 ms 20680 KB Output is correct
57 Correct 78 ms 20660 KB Output is correct
58 Correct 73 ms 20668 KB Output is correct
59 Correct 83 ms 20768 KB Output is correct
60 Correct 77 ms 20692 KB Output is correct
61 Correct 80 ms 20700 KB Output is correct
62 Correct 78 ms 20712 KB Output is correct
63 Correct 73 ms 20696 KB Output is correct
64 Correct 79 ms 20656 KB Output is correct
65 Correct 72 ms 20668 KB Output is correct
66 Correct 76 ms 20668 KB Output is correct
67 Correct 81 ms 20580 KB Output is correct
68 Correct 83 ms 20732 KB Output is correct
69 Correct 77 ms 20668 KB Output is correct
70 Correct 77 ms 20668 KB Output is correct
71 Correct 42 ms 18820 KB Output is correct
72 Correct 36 ms 18872 KB Output is correct
73 Correct 39 ms 18764 KB Output is correct
74 Correct 41 ms 18812 KB Output is correct
75 Correct 37 ms 18876 KB Output is correct
76 Correct 48 ms 19260 KB Output is correct
77 Correct 45 ms 19260 KB Output is correct
78 Correct 46 ms 19300 KB Output is correct
79 Correct 55 ms 19256 KB Output is correct
80 Correct 46 ms 19196 KB Output is correct
81 Correct 66 ms 20156 KB Output is correct
82 Correct 67 ms 20168 KB Output is correct
83 Correct 65 ms 20160 KB Output is correct
84 Correct 64 ms 20180 KB Output is correct
85 Correct 65 ms 20168 KB Output is correct
86 Correct 75 ms 20212 KB Output is correct
87 Correct 66 ms 20156 KB Output is correct
88 Correct 74 ms 20192 KB Output is correct
89 Correct 72 ms 20424 KB Output is correct
90 Correct 67 ms 20156 KB Output is correct
91 Correct 97 ms 20804 KB Output is correct
92 Correct 98 ms 20724 KB Output is correct
93 Correct 97 ms 20800 KB Output is correct
94 Correct 99 ms 20792 KB Output is correct
95 Correct 99 ms 20712 KB Output is correct
96 Correct 110 ms 21096 KB Output is correct
97 Correct 106 ms 21184 KB Output is correct
98 Correct 109 ms 21192 KB Output is correct
99 Correct 106 ms 21184 KB Output is correct
100 Correct 101 ms 21140 KB Output is correct
101 Correct 102 ms 21184 KB Output is correct
102 Correct 107 ms 21184 KB Output is correct
103 Correct 102 ms 21184 KB Output is correct
104 Correct 102 ms 21092 KB Output is correct
105 Correct 103 ms 21080 KB Output is correct
106 Correct 105 ms 21352 KB Output is correct
107 Correct 103 ms 21412 KB Output is correct
108 Correct 107 ms 21312 KB Output is correct
109 Correct 103 ms 21312 KB Output is correct
110 Correct 104 ms 21300 KB Output is correct
111 Correct 106 ms 21388 KB Output is correct
112 Correct 106 ms 21312 KB Output is correct
113 Correct 107 ms 21304 KB Output is correct
114 Correct 111 ms 21312 KB Output is correct
115 Correct 106 ms 21312 KB Output is correct
116 Incorrect 29 ms 18508 KB Output isn't correct
117 Halted 0 ms 0 KB -