답안 #709019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709019 2023-03-13T04:16:06 Z Sanzhar23 Diversity (CEOI21_diversity) C++14
64 / 100
72 ms 12128 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long	
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll> 
#define pii pair <int, int> 
#define triple pair <pair <ll, ll> , ll>   
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>

const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 3e5 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;

int n, q;
int a[N], cnt[N], pref[N], suf[N];

int main(){
	speed;
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		cnt[a[i]]++;
	}
	int l, r;
	cin >> l >> r;
	vector <pii> vt;
	for(int i = 1; i <= 300000; i++){
		if(cnt[i] != 0)
			vt.pb({cnt[i], i});
	}
	sort(all(vt));
	vector <int> nw;
	vector <pii> gt;
	gt.pb({0, 0});
	for(int i = 0; i < vt.size(); i++){
		int x = vt[i].S, col = vt[i].F;
		if(i % 2 == 0){
			gt.pb({x, col});
			for(int j = 0; j < col; j++){
				nw.pb(x);
			}	
		}
	}
	for(int i = vt.size() - 1; i >= 0; i--){
		int x = vt[i].S, col = vt[i].F;
		if(i % 2 == 1){
			gt.pb({x, col});
			for(int j = 0; j < col; j++){
				nw.pb(x);
			}
		}
	}
	ll ans = 0;
	/*
	for(int i = 0; i < nw.size(); i++){
		set <int> st;
		for(int j = i; j < nw.size(); j++){
			st.insert(nw[j]);
			ans += (int) st.size();
		}
	}
	*/
	int len = gt.size() - 1;
	for(int i = 1; i <= len; i++){
		pref[i] = pref[i - 1] + gt[i].S;
	}
	for(int i = len; i >= 1; i--){
		suf[i] = suf[i + 1] + gt[i].S;
	}
	for(int i = 1; i <= len; i++){
		int x = gt[i].F, col = gt[i].S;
		ll f1 = pref[i - 1] * 1ll * suf[i + 1];
		ll f2 = col * 1ll * (col + 1) / 2ll;
		ll f3 = col * 1ll * pref[i - 1];
		ll f4 = col * 1ll * suf[i + 1];
		ans += (f1 + f2 + f3 + f4);
	}
	cout << ans << endl;
}
/*	
%I64d6


		
		



%I64d
*/ 

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i = 0; i < vt.size(); i++){
      |                 ~~^~~~~~~~~~~
diversity.cpp:89:7: warning: unused variable 'x' [-Wunused-variable]
   89 |   int x = gt[i].F, col = gt[i].S;
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 1516 KB Output is correct
5 Correct 12 ms 2580 KB Output is correct
6 Correct 26 ms 4248 KB Output is correct
7 Correct 26 ms 4176 KB Output is correct
8 Correct 20 ms 4296 KB Output is correct
9 Correct 19 ms 4276 KB Output is correct
10 Correct 20 ms 4324 KB Output is correct
11 Correct 18 ms 4232 KB Output is correct
12 Correct 19 ms 4332 KB Output is correct
13 Correct 20 ms 4296 KB Output is correct
14 Correct 18 ms 4268 KB Output is correct
15 Correct 19 ms 4232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 1516 KB Output is correct
5 Correct 12 ms 2580 KB Output is correct
6 Correct 26 ms 4248 KB Output is correct
7 Correct 26 ms 4176 KB Output is correct
8 Correct 20 ms 4296 KB Output is correct
9 Correct 19 ms 4276 KB Output is correct
10 Correct 20 ms 4324 KB Output is correct
11 Correct 18 ms 4232 KB Output is correct
12 Correct 19 ms 4332 KB Output is correct
13 Correct 20 ms 4296 KB Output is correct
14 Correct 18 ms 4268 KB Output is correct
15 Correct 19 ms 4232 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 8 ms 1616 KB Output is correct
20 Correct 16 ms 2764 KB Output is correct
21 Correct 20 ms 4400 KB Output is correct
22 Correct 19 ms 4436 KB Output is correct
23 Correct 20 ms 4472 KB Output is correct
24 Correct 20 ms 4384 KB Output is correct
25 Correct 19 ms 4424 KB Output is correct
26 Correct 21 ms 4424 KB Output is correct
27 Correct 19 ms 4424 KB Output is correct
28 Correct 21 ms 4432 KB Output is correct
29 Correct 22 ms 4364 KB Output is correct
30 Correct 27 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 1516 KB Output is correct
5 Correct 12 ms 2580 KB Output is correct
6 Correct 26 ms 4248 KB Output is correct
7 Correct 26 ms 4176 KB Output is correct
8 Correct 20 ms 4296 KB Output is correct
9 Correct 19 ms 4276 KB Output is correct
10 Correct 20 ms 4324 KB Output is correct
11 Correct 18 ms 4232 KB Output is correct
12 Correct 19 ms 4332 KB Output is correct
13 Correct 20 ms 4296 KB Output is correct
14 Correct 18 ms 4268 KB Output is correct
15 Correct 19 ms 4232 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 8 ms 1616 KB Output is correct
20 Correct 16 ms 2764 KB Output is correct
21 Correct 20 ms 4400 KB Output is correct
22 Correct 19 ms 4436 KB Output is correct
23 Correct 20 ms 4472 KB Output is correct
24 Correct 20 ms 4384 KB Output is correct
25 Correct 19 ms 4424 KB Output is correct
26 Correct 21 ms 4424 KB Output is correct
27 Correct 19 ms 4424 KB Output is correct
28 Correct 21 ms 4432 KB Output is correct
29 Correct 22 ms 4364 KB Output is correct
30 Correct 27 ms 4444 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 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 4 ms 1028 KB Output is correct
38 Correct 4 ms 1040 KB Output is correct
39 Correct 7 ms 1752 KB Output is correct
40 Correct 15 ms 2984 KB Output is correct
41 Correct 29 ms 4816 KB Output is correct
42 Correct 23 ms 4744 KB Output is correct
43 Correct 24 ms 4832 KB Output is correct
44 Correct 23 ms 4788 KB Output is correct
45 Correct 21 ms 4804 KB Output is correct
46 Correct 20 ms 4812 KB Output is correct
47 Correct 21 ms 4788 KB Output is correct
48 Correct 21 ms 4776 KB Output is correct
49 Correct 20 ms 4788 KB Output is correct
50 Correct 23 ms 4792 KB Output is correct
51 Correct 22 ms 4860 KB Output is correct
52 Correct 21 ms 4764 KB Output is correct
53 Correct 22 ms 4776 KB Output is correct
54 Correct 21 ms 4780 KB Output is correct
55 Correct 23 ms 4736 KB Output is correct
56 Correct 21 ms 4788 KB Output is correct
57 Correct 23 ms 4812 KB Output is correct
58 Correct 22 ms 4812 KB Output is correct
59 Correct 21 ms 4812 KB Output is correct
60 Correct 21 ms 4788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 7 ms 1516 KB Output is correct
15 Correct 12 ms 2580 KB Output is correct
16 Correct 26 ms 4248 KB Output is correct
17 Correct 26 ms 4176 KB Output is correct
18 Correct 20 ms 4296 KB Output is correct
19 Correct 19 ms 4276 KB Output is correct
20 Correct 20 ms 4324 KB Output is correct
21 Correct 18 ms 4232 KB Output is correct
22 Correct 19 ms 4332 KB Output is correct
23 Correct 20 ms 4296 KB Output is correct
24 Correct 18 ms 4268 KB Output is correct
25 Correct 19 ms 4232 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 8 ms 1616 KB Output is correct
30 Correct 16 ms 2764 KB Output is correct
31 Correct 20 ms 4400 KB Output is correct
32 Correct 19 ms 4436 KB Output is correct
33 Correct 20 ms 4472 KB Output is correct
34 Correct 20 ms 4384 KB Output is correct
35 Correct 19 ms 4424 KB Output is correct
36 Correct 21 ms 4424 KB Output is correct
37 Correct 19 ms 4424 KB Output is correct
38 Correct 21 ms 4432 KB Output is correct
39 Correct 22 ms 4364 KB Output is correct
40 Correct 27 ms 4444 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 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 4 ms 1028 KB Output is correct
48 Correct 4 ms 1040 KB Output is correct
49 Correct 7 ms 1752 KB Output is correct
50 Correct 15 ms 2984 KB Output is correct
51 Correct 29 ms 4816 KB Output is correct
52 Correct 23 ms 4744 KB Output is correct
53 Correct 24 ms 4832 KB Output is correct
54 Correct 23 ms 4788 KB Output is correct
55 Correct 21 ms 4804 KB Output is correct
56 Correct 20 ms 4812 KB Output is correct
57 Correct 21 ms 4788 KB Output is correct
58 Correct 21 ms 4776 KB Output is correct
59 Correct 20 ms 4788 KB Output is correct
60 Correct 23 ms 4792 KB Output is correct
61 Correct 22 ms 4860 KB Output is correct
62 Correct 21 ms 4764 KB Output is correct
63 Correct 22 ms 4776 KB Output is correct
64 Correct 21 ms 4780 KB Output is correct
65 Correct 23 ms 4736 KB Output is correct
66 Correct 21 ms 4788 KB Output is correct
67 Correct 23 ms 4812 KB Output is correct
68 Correct 22 ms 4812 KB Output is correct
69 Correct 21 ms 4812 KB Output is correct
70 Correct 21 ms 4788 KB Output is correct
71 Correct 5 ms 1140 KB Output is correct
72 Correct 5 ms 1132 KB Output is correct
73 Correct 6 ms 1172 KB Output is correct
74 Correct 5 ms 1172 KB Output is correct
75 Correct 5 ms 1140 KB Output is correct
76 Correct 12 ms 1872 KB Output is correct
77 Correct 12 ms 1880 KB Output is correct
78 Correct 10 ms 1872 KB Output is correct
79 Correct 9 ms 1872 KB Output is correct
80 Correct 9 ms 1896 KB Output is correct
81 Correct 17 ms 3412 KB Output is correct
82 Correct 17 ms 3416 KB Output is correct
83 Correct 17 ms 3408 KB Output is correct
84 Correct 17 ms 3372 KB Output is correct
85 Correct 16 ms 3472 KB Output is correct
86 Correct 19 ms 3536 KB Output is correct
87 Correct 19 ms 3596 KB Output is correct
88 Correct 21 ms 3652 KB Output is correct
89 Correct 20 ms 3540 KB Output is correct
90 Correct 21 ms 3672 KB Output is correct
91 Correct 50 ms 7608 KB Output is correct
92 Correct 38 ms 7560 KB Output is correct
93 Correct 39 ms 7568 KB Output is correct
94 Correct 38 ms 7624 KB Output is correct
95 Correct 42 ms 7580 KB Output is correct
96 Correct 55 ms 11124 KB Output is correct
97 Correct 49 ms 11004 KB Output is correct
98 Correct 51 ms 11056 KB Output is correct
99 Correct 57 ms 11116 KB Output is correct
100 Correct 54 ms 11056 KB Output is correct
101 Correct 66 ms 11112 KB Output is correct
102 Correct 59 ms 11076 KB Output is correct
103 Correct 60 ms 11128 KB Output is correct
104 Correct 48 ms 11108 KB Output is correct
105 Correct 52 ms 11124 KB Output is correct
106 Correct 57 ms 12096 KB Output is correct
107 Correct 65 ms 12052 KB Output is correct
108 Correct 72 ms 12124 KB Output is correct
109 Correct 52 ms 12100 KB Output is correct
110 Correct 62 ms 12036 KB Output is correct
111 Correct 58 ms 12128 KB Output is correct
112 Correct 51 ms 12104 KB Output is correct
113 Correct 60 ms 12128 KB Output is correct
114 Correct 58 ms 12100 KB Output is correct
115 Correct 55 ms 12092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 7 ms 1516 KB Output is correct
15 Correct 12 ms 2580 KB Output is correct
16 Correct 26 ms 4248 KB Output is correct
17 Correct 26 ms 4176 KB Output is correct
18 Correct 20 ms 4296 KB Output is correct
19 Correct 19 ms 4276 KB Output is correct
20 Correct 20 ms 4324 KB Output is correct
21 Correct 18 ms 4232 KB Output is correct
22 Correct 19 ms 4332 KB Output is correct
23 Correct 20 ms 4296 KB Output is correct
24 Correct 18 ms 4268 KB Output is correct
25 Correct 19 ms 4232 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 8 ms 1616 KB Output is correct
30 Correct 16 ms 2764 KB Output is correct
31 Correct 20 ms 4400 KB Output is correct
32 Correct 19 ms 4436 KB Output is correct
33 Correct 20 ms 4472 KB Output is correct
34 Correct 20 ms 4384 KB Output is correct
35 Correct 19 ms 4424 KB Output is correct
36 Correct 21 ms 4424 KB Output is correct
37 Correct 19 ms 4424 KB Output is correct
38 Correct 21 ms 4432 KB Output is correct
39 Correct 22 ms 4364 KB Output is correct
40 Correct 27 ms 4444 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 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 4 ms 1028 KB Output is correct
48 Correct 4 ms 1040 KB Output is correct
49 Correct 7 ms 1752 KB Output is correct
50 Correct 15 ms 2984 KB Output is correct
51 Correct 29 ms 4816 KB Output is correct
52 Correct 23 ms 4744 KB Output is correct
53 Correct 24 ms 4832 KB Output is correct
54 Correct 23 ms 4788 KB Output is correct
55 Correct 21 ms 4804 KB Output is correct
56 Correct 20 ms 4812 KB Output is correct
57 Correct 21 ms 4788 KB Output is correct
58 Correct 21 ms 4776 KB Output is correct
59 Correct 20 ms 4788 KB Output is correct
60 Correct 23 ms 4792 KB Output is correct
61 Correct 22 ms 4860 KB Output is correct
62 Correct 21 ms 4764 KB Output is correct
63 Correct 22 ms 4776 KB Output is correct
64 Correct 21 ms 4780 KB Output is correct
65 Correct 23 ms 4736 KB Output is correct
66 Correct 21 ms 4788 KB Output is correct
67 Correct 23 ms 4812 KB Output is correct
68 Correct 22 ms 4812 KB Output is correct
69 Correct 21 ms 4812 KB Output is correct
70 Correct 21 ms 4788 KB Output is correct
71 Correct 5 ms 1140 KB Output is correct
72 Correct 5 ms 1132 KB Output is correct
73 Correct 6 ms 1172 KB Output is correct
74 Correct 5 ms 1172 KB Output is correct
75 Correct 5 ms 1140 KB Output is correct
76 Correct 12 ms 1872 KB Output is correct
77 Correct 12 ms 1880 KB Output is correct
78 Correct 10 ms 1872 KB Output is correct
79 Correct 9 ms 1872 KB Output is correct
80 Correct 9 ms 1896 KB Output is correct
81 Correct 17 ms 3412 KB Output is correct
82 Correct 17 ms 3416 KB Output is correct
83 Correct 17 ms 3408 KB Output is correct
84 Correct 17 ms 3372 KB Output is correct
85 Correct 16 ms 3472 KB Output is correct
86 Correct 19 ms 3536 KB Output is correct
87 Correct 19 ms 3596 KB Output is correct
88 Correct 21 ms 3652 KB Output is correct
89 Correct 20 ms 3540 KB Output is correct
90 Correct 21 ms 3672 KB Output is correct
91 Correct 50 ms 7608 KB Output is correct
92 Correct 38 ms 7560 KB Output is correct
93 Correct 39 ms 7568 KB Output is correct
94 Correct 38 ms 7624 KB Output is correct
95 Correct 42 ms 7580 KB Output is correct
96 Correct 55 ms 11124 KB Output is correct
97 Correct 49 ms 11004 KB Output is correct
98 Correct 51 ms 11056 KB Output is correct
99 Correct 57 ms 11116 KB Output is correct
100 Correct 54 ms 11056 KB Output is correct
101 Correct 66 ms 11112 KB Output is correct
102 Correct 59 ms 11076 KB Output is correct
103 Correct 60 ms 11128 KB Output is correct
104 Correct 48 ms 11108 KB Output is correct
105 Correct 52 ms 11124 KB Output is correct
106 Correct 57 ms 12096 KB Output is correct
107 Correct 65 ms 12052 KB Output is correct
108 Correct 72 ms 12124 KB Output is correct
109 Correct 52 ms 12100 KB Output is correct
110 Correct 62 ms 12036 KB Output is correct
111 Correct 58 ms 12128 KB Output is correct
112 Correct 51 ms 12104 KB Output is correct
113 Correct 60 ms 12128 KB Output is correct
114 Correct 58 ms 12100 KB Output is correct
115 Correct 55 ms 12092 KB Output is correct
116 Incorrect 2 ms 596 KB Output isn't correct
117 Halted 0 ms 0 KB -