답안 #617212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617212 2022-08-01T09:38:31 Z Mr_Husanboy Diversity (CEOI21_diversity) C++14
38 / 100
7000 ms 9048 KB
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>


 
 
using namespace std;
using ll = long long;


 
mt19937 rng(123);
#define ld long double
#define ull unsigned long long 
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define setp(x) setprecision(x)


ll mod=1e9+7;
int inf=1e9;
const int LOGN = 20;
const int MXX=3e5;

const long double PI = 3.1415926535897932384626433832795;




ll calc(deque<ll> v){
	ll ans = 0;
	for(auto u : v) ans += (u+1)*u/2;
	int n = v.size();
	for(ll i = 0; i < n; i ++){
		for(ll j = i + 1; j < n; j ++){
			ans += (j-i + 1) * (v[j] * v[i]);
		}
	}
	return ans;
}

ll calcc(deque<int> v){
	int ans = 0;
	int n = v.size();
	for(int i = 0; i < n; i ++){
		set<int> st;
		for(int j = i; j < n; j ++){
			st.insert(v[j]); ans += st.size();
		}
	}
	return ans;
}


void solve(){
	int n, q; cin >> n >> q;
	map<int,int> mp;
	for(int i = 0; i<n; i ++){
		int x; cin >> x; x --;
		mp[x] ++;
	}
	vector<pair<int,int>> v;
	for(auto u : mp){
		v.push_back({u.ss,u.ff});
	}
	sort(all(v), greater<>());
//	for(auto u : v) cout << u.ff << ' ' << u.ss << endl;cout << endl;
	deque<int> a;
	int col = 1;
	deque<ll> arr;
	for(auto u : v){
		int tem = u.ff;
		if(col){
		//	while(tem --){ a.push_back(u.ss);}
			arr.push_back(u.ff);
		}else{
		//	while(tem --){	a.push_front(u.ss);}
			arr.push_front(u.ff);
		}
		col^=1;
	}
	
	
	cout << calc(arr);// << ' ' << calcc(a);
}

 
int main(){
	int testcases = 1;
//	cin >> testcases;
	while(testcases --){
		solve(); if(testcases) cout << '\n';
		cout << endl;
	}
} 

Compilation message

diversity.cpp: In function 'void solve()':
diversity.cpp:80:7: warning: unused variable 'tem' [-Wunused-variable]
   80 |   int tem = u.ff;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 15 ms 296 KB Output is correct
5 Correct 30 ms 680 KB Output is correct
6 Correct 51 ms 912 KB Output is correct
7 Correct 54 ms 888 KB Output is correct
8 Correct 46 ms 852 KB Output is correct
9 Correct 54 ms 908 KB Output is correct
10 Correct 56 ms 944 KB Output is correct
11 Correct 51 ms 924 KB Output is correct
12 Correct 62 ms 948 KB Output is correct
13 Correct 48 ms 908 KB Output is correct
14 Correct 47 ms 904 KB Output is correct
15 Correct 48 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 15 ms 296 KB Output is correct
5 Correct 30 ms 680 KB Output is correct
6 Correct 51 ms 912 KB Output is correct
7 Correct 54 ms 888 KB Output is correct
8 Correct 46 ms 852 KB Output is correct
9 Correct 54 ms 908 KB Output is correct
10 Correct 56 ms 944 KB Output is correct
11 Correct 51 ms 924 KB Output is correct
12 Correct 62 ms 948 KB Output is correct
13 Correct 48 ms 908 KB Output is correct
14 Correct 47 ms 904 KB Output is correct
15 Correct 48 ms 916 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 3 ms 312 KB Output is correct
19 Correct 26 ms 444 KB Output is correct
20 Correct 39 ms 788 KB Output is correct
21 Correct 58 ms 1096 KB Output is correct
22 Correct 52 ms 1028 KB Output is correct
23 Correct 56 ms 1028 KB Output is correct
24 Correct 62 ms 1028 KB Output is correct
25 Correct 56 ms 1060 KB Output is correct
26 Correct 52 ms 1044 KB Output is correct
27 Correct 54 ms 1040 KB Output is correct
28 Correct 52 ms 1040 KB Output is correct
29 Correct 53 ms 1040 KB Output is correct
30 Correct 55 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 15 ms 296 KB Output is correct
5 Correct 30 ms 680 KB Output is correct
6 Correct 51 ms 912 KB Output is correct
7 Correct 54 ms 888 KB Output is correct
8 Correct 46 ms 852 KB Output is correct
9 Correct 54 ms 908 KB Output is correct
10 Correct 56 ms 944 KB Output is correct
11 Correct 51 ms 924 KB Output is correct
12 Correct 62 ms 948 KB Output is correct
13 Correct 48 ms 908 KB Output is correct
14 Correct 47 ms 904 KB Output is correct
15 Correct 48 ms 916 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 3 ms 312 KB Output is correct
19 Correct 26 ms 444 KB Output is correct
20 Correct 39 ms 788 KB Output is correct
21 Correct 58 ms 1096 KB Output is correct
22 Correct 52 ms 1028 KB Output is correct
23 Correct 56 ms 1028 KB Output is correct
24 Correct 62 ms 1028 KB Output is correct
25 Correct 56 ms 1060 KB Output is correct
26 Correct 52 ms 1044 KB Output is correct
27 Correct 54 ms 1040 KB Output is correct
28 Correct 52 ms 1040 KB Output is correct
29 Correct 53 ms 1040 KB Output is correct
30 Correct 55 ms 1048 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 15 ms 440 KB Output is correct
38 Correct 18 ms 536 KB Output is correct
39 Correct 28 ms 712 KB Output is correct
40 Correct 56 ms 1092 KB Output is correct
41 Correct 84 ms 1596 KB Output is correct
42 Correct 87 ms 1476 KB Output is correct
43 Correct 78 ms 1464 KB Output is correct
44 Correct 78 ms 1472 KB Output is correct
45 Correct 76 ms 1484 KB Output is correct
46 Correct 81 ms 1464 KB Output is correct
47 Correct 88 ms 1468 KB Output is correct
48 Correct 90 ms 1460 KB Output is correct
49 Correct 83 ms 1476 KB Output is correct
50 Correct 89 ms 1460 KB Output is correct
51 Correct 79 ms 1472 KB Output is correct
52 Correct 80 ms 1472 KB Output is correct
53 Correct 87 ms 1464 KB Output is correct
54 Correct 103 ms 1460 KB Output is correct
55 Correct 89 ms 1464 KB Output is correct
56 Correct 77 ms 1476 KB Output is correct
57 Correct 80 ms 1468 KB Output is correct
58 Correct 85 ms 1464 KB Output is correct
59 Correct 84 ms 1460 KB Output is correct
60 Correct 84 ms 1472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 15 ms 296 KB Output is correct
15 Correct 30 ms 680 KB Output is correct
16 Correct 51 ms 912 KB Output is correct
17 Correct 54 ms 888 KB Output is correct
18 Correct 46 ms 852 KB Output is correct
19 Correct 54 ms 908 KB Output is correct
20 Correct 56 ms 944 KB Output is correct
21 Correct 51 ms 924 KB Output is correct
22 Correct 62 ms 948 KB Output is correct
23 Correct 48 ms 908 KB Output is correct
24 Correct 47 ms 904 KB Output is correct
25 Correct 48 ms 916 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 312 KB Output is correct
29 Correct 26 ms 444 KB Output is correct
30 Correct 39 ms 788 KB Output is correct
31 Correct 58 ms 1096 KB Output is correct
32 Correct 52 ms 1028 KB Output is correct
33 Correct 56 ms 1028 KB Output is correct
34 Correct 62 ms 1028 KB Output is correct
35 Correct 56 ms 1060 KB Output is correct
36 Correct 52 ms 1044 KB Output is correct
37 Correct 54 ms 1040 KB Output is correct
38 Correct 52 ms 1040 KB Output is correct
39 Correct 53 ms 1040 KB Output is correct
40 Correct 55 ms 1048 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 336 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 15 ms 440 KB Output is correct
48 Correct 18 ms 536 KB Output is correct
49 Correct 28 ms 712 KB Output is correct
50 Correct 56 ms 1092 KB Output is correct
51 Correct 84 ms 1596 KB Output is correct
52 Correct 87 ms 1476 KB Output is correct
53 Correct 78 ms 1464 KB Output is correct
54 Correct 78 ms 1472 KB Output is correct
55 Correct 76 ms 1484 KB Output is correct
56 Correct 81 ms 1464 KB Output is correct
57 Correct 88 ms 1468 KB Output is correct
58 Correct 90 ms 1460 KB Output is correct
59 Correct 83 ms 1476 KB Output is correct
60 Correct 89 ms 1460 KB Output is correct
61 Correct 79 ms 1472 KB Output is correct
62 Correct 80 ms 1472 KB Output is correct
63 Correct 87 ms 1464 KB Output is correct
64 Correct 103 ms 1460 KB Output is correct
65 Correct 89 ms 1464 KB Output is correct
66 Correct 77 ms 1476 KB Output is correct
67 Correct 80 ms 1468 KB Output is correct
68 Correct 85 ms 1464 KB Output is correct
69 Correct 84 ms 1460 KB Output is correct
70 Correct 84 ms 1472 KB Output is correct
71 Correct 18 ms 612 KB Output is correct
72 Correct 18 ms 572 KB Output is correct
73 Correct 18 ms 608 KB Output is correct
74 Correct 19 ms 644 KB Output is correct
75 Correct 17 ms 596 KB Output is correct
76 Correct 49 ms 1108 KB Output is correct
77 Correct 65 ms 996 KB Output is correct
78 Correct 49 ms 1108 KB Output is correct
79 Correct 49 ms 1008 KB Output is correct
80 Correct 48 ms 1112 KB Output is correct
81 Correct 134 ms 1960 KB Output is correct
82 Correct 175 ms 1960 KB Output is correct
83 Correct 136 ms 1960 KB Output is correct
84 Correct 135 ms 1968 KB Output is correct
85 Correct 141 ms 1956 KB Output is correct
86 Correct 377 ms 2788 KB Output is correct
87 Correct 393 ms 2788 KB Output is correct
88 Correct 391 ms 2788 KB Output is correct
89 Correct 375 ms 2788 KB Output is correct
90 Correct 345 ms 2784 KB Output is correct
91 Execution timed out 7062 ms 9048 KB Time limit exceeded
92 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 216 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 15 ms 296 KB Output is correct
15 Correct 30 ms 680 KB Output is correct
16 Correct 51 ms 912 KB Output is correct
17 Correct 54 ms 888 KB Output is correct
18 Correct 46 ms 852 KB Output is correct
19 Correct 54 ms 908 KB Output is correct
20 Correct 56 ms 944 KB Output is correct
21 Correct 51 ms 924 KB Output is correct
22 Correct 62 ms 948 KB Output is correct
23 Correct 48 ms 908 KB Output is correct
24 Correct 47 ms 904 KB Output is correct
25 Correct 48 ms 916 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 3 ms 312 KB Output is correct
29 Correct 26 ms 444 KB Output is correct
30 Correct 39 ms 788 KB Output is correct
31 Correct 58 ms 1096 KB Output is correct
32 Correct 52 ms 1028 KB Output is correct
33 Correct 56 ms 1028 KB Output is correct
34 Correct 62 ms 1028 KB Output is correct
35 Correct 56 ms 1060 KB Output is correct
36 Correct 52 ms 1044 KB Output is correct
37 Correct 54 ms 1040 KB Output is correct
38 Correct 52 ms 1040 KB Output is correct
39 Correct 53 ms 1040 KB Output is correct
40 Correct 55 ms 1048 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 336 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 4 ms 340 KB Output is correct
47 Correct 15 ms 440 KB Output is correct
48 Correct 18 ms 536 KB Output is correct
49 Correct 28 ms 712 KB Output is correct
50 Correct 56 ms 1092 KB Output is correct
51 Correct 84 ms 1596 KB Output is correct
52 Correct 87 ms 1476 KB Output is correct
53 Correct 78 ms 1464 KB Output is correct
54 Correct 78 ms 1472 KB Output is correct
55 Correct 76 ms 1484 KB Output is correct
56 Correct 81 ms 1464 KB Output is correct
57 Correct 88 ms 1468 KB Output is correct
58 Correct 90 ms 1460 KB Output is correct
59 Correct 83 ms 1476 KB Output is correct
60 Correct 89 ms 1460 KB Output is correct
61 Correct 79 ms 1472 KB Output is correct
62 Correct 80 ms 1472 KB Output is correct
63 Correct 87 ms 1464 KB Output is correct
64 Correct 103 ms 1460 KB Output is correct
65 Correct 89 ms 1464 KB Output is correct
66 Correct 77 ms 1476 KB Output is correct
67 Correct 80 ms 1468 KB Output is correct
68 Correct 85 ms 1464 KB Output is correct
69 Correct 84 ms 1460 KB Output is correct
70 Correct 84 ms 1472 KB Output is correct
71 Correct 18 ms 612 KB Output is correct
72 Correct 18 ms 572 KB Output is correct
73 Correct 18 ms 608 KB Output is correct
74 Correct 19 ms 644 KB Output is correct
75 Correct 17 ms 596 KB Output is correct
76 Correct 49 ms 1108 KB Output is correct
77 Correct 65 ms 996 KB Output is correct
78 Correct 49 ms 1108 KB Output is correct
79 Correct 49 ms 1008 KB Output is correct
80 Correct 48 ms 1112 KB Output is correct
81 Correct 134 ms 1960 KB Output is correct
82 Correct 175 ms 1960 KB Output is correct
83 Correct 136 ms 1960 KB Output is correct
84 Correct 135 ms 1968 KB Output is correct
85 Correct 141 ms 1956 KB Output is correct
86 Correct 377 ms 2788 KB Output is correct
87 Correct 393 ms 2788 KB Output is correct
88 Correct 391 ms 2788 KB Output is correct
89 Correct 375 ms 2788 KB Output is correct
90 Correct 345 ms 2784 KB Output is correct
91 Execution timed out 7062 ms 9048 KB Time limit exceeded
92 Halted 0 ms 0 KB -