답안 #772301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772301 2023-07-03T23:30:06 Z tolbi Diversity (CEOI21_diversity) C++17
64 / 100
4700 ms 22244 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz!..
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& is, pair<X,Y> &pr){return is>>pr.first>>pr.second;}
template<typename X, size_t Y> istream& operator>>(istream& is, array<X,Y> arr){for (auto &it : arr) is>>it; return is;}
template<typename T> istream& operator>>(istream& is, vector<T> arr){for (auto &it : arr) is>>it; return is;}
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define endl '\n'
#define int long long
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vint(x) vector<int> x
#define cinarr(x) for(auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define rev(x) reverse(x.begin(), x.end())
#define tol(bi) (1LL<<((int)(bi)))
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
int32_t main(){
	ios;
	int T = 1;
	if (!T) cin>>T;
	int tno = 0;
	while (T-(tno++)){
		deci(n);deci(q);
		vint(arr(n));
		cinarr(arr);
		while (q--){
			deci(l);deci(r);
			l--,r--;
			map<int,int> mp;
			for (int i = l; i <= r; i++){
				mp[arr[i]]++;
			}
			arr.clear();
			for (auto it : mp){
				arr.push_back(it.second);
			}
			sortarr(arr);
			vector<int> barr(arr.size(),0);
			int rp = barr.size()-1;
			int lp = 0;
			int lek = 0;
			int rek = 0;
			for (int i = 0; i < arr.size(); i++){
				if (lek<rek){
					barr[lp]=arr[i];
					lp++;
					lek+=arr[i];
				}
				else{
					barr[rp]=arr[i];
					rp--;
					rek+=arr[i];
				}
			}
			int ans = (n*(n+1)/2)*(int)barr.size();
			int somma = 0;
			for (int i = 0; i < barr.size(); i++){
				ans-=somma*(somma+1)/2;
				somma+=barr[i];
			}
			somma=0;
			for (int i = 0; i < barr.size(); i++){
				ans-=somma*(somma+1)/2;
				somma+=barr[barr.size()-i-1];
			}
			cout<<ans<<endl;
		}
	}
}

Compilation message

diversity.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
diversity.cpp: In function 'int32_t main()':
diversity.cpp:56:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    for (int i = 0; i < arr.size(); i++){
      |                    ~~^~~~~~~~~~~~
diversity.cpp:70:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    for (int i = 0; i < barr.size(); i++){
      |                    ~~^~~~~~~~~~~~~
diversity.cpp:75:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |    for (int i = 0; i < barr.size(); i++){
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 212 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 324 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 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 11 ms 2272 KB Output is correct
6 Correct 17 ms 3284 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 17 ms 3284 KB Output is correct
9 Correct 17 ms 3312 KB Output is correct
10 Correct 18 ms 3320 KB Output is correct
11 Correct 17 ms 3284 KB Output is correct
12 Correct 18 ms 3316 KB Output is correct
13 Correct 17 ms 3284 KB Output is correct
14 Correct 18 ms 3280 KB Output is correct
15 Correct 18 ms 3312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 11 ms 2272 KB Output is correct
6 Correct 17 ms 3284 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 17 ms 3284 KB Output is correct
9 Correct 17 ms 3312 KB Output is correct
10 Correct 18 ms 3320 KB Output is correct
11 Correct 17 ms 3284 KB Output is correct
12 Correct 18 ms 3316 KB Output is correct
13 Correct 17 ms 3284 KB Output is correct
14 Correct 18 ms 3280 KB Output is correct
15 Correct 18 ms 3312 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 7 ms 1364 KB Output is correct
20 Correct 13 ms 2388 KB Output is correct
21 Correct 23 ms 3432 KB Output is correct
22 Correct 20 ms 3444 KB Output is correct
23 Correct 20 ms 3412 KB Output is correct
24 Correct 20 ms 3412 KB Output is correct
25 Correct 20 ms 3412 KB Output is correct
26 Correct 26 ms 3436 KB Output is correct
27 Correct 20 ms 3444 KB Output is correct
28 Correct 19 ms 3412 KB Output is correct
29 Correct 20 ms 3320 KB Output is correct
30 Correct 20 ms 3440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 11 ms 2272 KB Output is correct
6 Correct 17 ms 3284 KB Output is correct
7 Correct 16 ms 3284 KB Output is correct
8 Correct 17 ms 3284 KB Output is correct
9 Correct 17 ms 3312 KB Output is correct
10 Correct 18 ms 3320 KB Output is correct
11 Correct 17 ms 3284 KB Output is correct
12 Correct 18 ms 3316 KB Output is correct
13 Correct 17 ms 3284 KB Output is correct
14 Correct 18 ms 3280 KB Output is correct
15 Correct 18 ms 3312 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 7 ms 1364 KB Output is correct
20 Correct 13 ms 2388 KB Output is correct
21 Correct 23 ms 3432 KB Output is correct
22 Correct 20 ms 3444 KB Output is correct
23 Correct 20 ms 3412 KB Output is correct
24 Correct 20 ms 3412 KB Output is correct
25 Correct 20 ms 3412 KB Output is correct
26 Correct 26 ms 3436 KB Output is correct
27 Correct 20 ms 3444 KB Output is correct
28 Correct 19 ms 3412 KB Output is correct
29 Correct 20 ms 3320 KB Output is correct
30 Correct 20 ms 3440 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 6 ms 848 KB Output is correct
38 Correct 6 ms 980 KB Output is correct
39 Correct 12 ms 1496 KB Output is correct
40 Correct 21 ms 2668 KB Output is correct
41 Correct 31 ms 3880 KB Output is correct
42 Correct 31 ms 3796 KB Output is correct
43 Correct 32 ms 3868 KB Output is correct
44 Correct 31 ms 3884 KB Output is correct
45 Correct 32 ms 3824 KB Output is correct
46 Correct 35 ms 3828 KB Output is correct
47 Correct 32 ms 3812 KB Output is correct
48 Correct 31 ms 3788 KB Output is correct
49 Correct 31 ms 3824 KB Output is correct
50 Correct 31 ms 3796 KB Output is correct
51 Correct 31 ms 3876 KB Output is correct
52 Correct 31 ms 3796 KB Output is correct
53 Correct 32 ms 3828 KB Output is correct
54 Correct 31 ms 3888 KB Output is correct
55 Correct 30 ms 3788 KB Output is correct
56 Correct 31 ms 3896 KB Output is correct
57 Correct 31 ms 3820 KB Output is correct
58 Correct 32 ms 3812 KB Output is correct
59 Correct 30 ms 3796 KB Output is correct
60 Correct 31 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 212 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 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 11 ms 2272 KB Output is correct
16 Correct 17 ms 3284 KB Output is correct
17 Correct 16 ms 3284 KB Output is correct
18 Correct 17 ms 3284 KB Output is correct
19 Correct 17 ms 3312 KB Output is correct
20 Correct 18 ms 3320 KB Output is correct
21 Correct 17 ms 3284 KB Output is correct
22 Correct 18 ms 3316 KB Output is correct
23 Correct 17 ms 3284 KB Output is correct
24 Correct 18 ms 3280 KB Output is correct
25 Correct 18 ms 3312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 7 ms 1364 KB Output is correct
30 Correct 13 ms 2388 KB Output is correct
31 Correct 23 ms 3432 KB Output is correct
32 Correct 20 ms 3444 KB Output is correct
33 Correct 20 ms 3412 KB Output is correct
34 Correct 20 ms 3412 KB Output is correct
35 Correct 20 ms 3412 KB Output is correct
36 Correct 26 ms 3436 KB Output is correct
37 Correct 20 ms 3444 KB Output is correct
38 Correct 19 ms 3412 KB Output is correct
39 Correct 20 ms 3320 KB Output is correct
40 Correct 20 ms 3440 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 320 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 6 ms 848 KB Output is correct
48 Correct 6 ms 980 KB Output is correct
49 Correct 12 ms 1496 KB Output is correct
50 Correct 21 ms 2668 KB Output is correct
51 Correct 31 ms 3880 KB Output is correct
52 Correct 31 ms 3796 KB Output is correct
53 Correct 32 ms 3868 KB Output is correct
54 Correct 31 ms 3884 KB Output is correct
55 Correct 32 ms 3824 KB Output is correct
56 Correct 35 ms 3828 KB Output is correct
57 Correct 32 ms 3812 KB Output is correct
58 Correct 31 ms 3788 KB Output is correct
59 Correct 31 ms 3824 KB Output is correct
60 Correct 31 ms 3796 KB Output is correct
61 Correct 31 ms 3876 KB Output is correct
62 Correct 31 ms 3796 KB Output is correct
63 Correct 32 ms 3828 KB Output is correct
64 Correct 31 ms 3888 KB Output is correct
65 Correct 30 ms 3788 KB Output is correct
66 Correct 31 ms 3896 KB Output is correct
67 Correct 31 ms 3820 KB Output is correct
68 Correct 32 ms 3812 KB Output is correct
69 Correct 30 ms 3796 KB Output is correct
70 Correct 31 ms 3796 KB Output is correct
71 Correct 8 ms 980 KB Output is correct
72 Correct 7 ms 1072 KB Output is correct
73 Correct 7 ms 980 KB Output is correct
74 Correct 6 ms 980 KB Output is correct
75 Correct 7 ms 1076 KB Output is correct
76 Correct 14 ms 1876 KB Output is correct
77 Correct 14 ms 1868 KB Output is correct
78 Correct 14 ms 1864 KB Output is correct
79 Correct 15 ms 1876 KB Output is correct
80 Correct 14 ms 1876 KB Output is correct
81 Correct 31 ms 3528 KB Output is correct
82 Correct 31 ms 3528 KB Output is correct
83 Correct 32 ms 3456 KB Output is correct
84 Correct 32 ms 3460 KB Output is correct
85 Correct 31 ms 3464 KB Output is correct
86 Correct 38 ms 4324 KB Output is correct
87 Correct 37 ms 4324 KB Output is correct
88 Correct 39 ms 4244 KB Output is correct
89 Correct 39 ms 4288 KB Output is correct
90 Correct 39 ms 4316 KB Output is correct
91 Correct 85 ms 11352 KB Output is correct
92 Correct 85 ms 11376 KB Output is correct
93 Correct 102 ms 11428 KB Output is correct
94 Correct 89 ms 11436 KB Output is correct
95 Correct 83 ms 11368 KB Output is correct
96 Correct 128 ms 18632 KB Output is correct
97 Correct 123 ms 18648 KB Output is correct
98 Correct 122 ms 18632 KB Output is correct
99 Correct 115 ms 18620 KB Output is correct
100 Correct 123 ms 18632 KB Output is correct
101 Correct 132 ms 18532 KB Output is correct
102 Correct 138 ms 18624 KB Output is correct
103 Correct 115 ms 18624 KB Output is correct
104 Correct 119 ms 18552 KB Output is correct
105 Correct 144 ms 18544 KB Output is correct
106 Correct 178 ms 22172 KB Output is correct
107 Correct 134 ms 22128 KB Output is correct
108 Correct 167 ms 22172 KB Output is correct
109 Correct 157 ms 22104 KB Output is correct
110 Correct 158 ms 22220 KB Output is correct
111 Correct 142 ms 22108 KB Output is correct
112 Correct 142 ms 22104 KB Output is correct
113 Correct 141 ms 22172 KB Output is correct
114 Correct 160 ms 22244 KB Output is correct
115 Correct 144 ms 22192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 0 ms 212 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 324 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 11 ms 2272 KB Output is correct
16 Correct 17 ms 3284 KB Output is correct
17 Correct 16 ms 3284 KB Output is correct
18 Correct 17 ms 3284 KB Output is correct
19 Correct 17 ms 3312 KB Output is correct
20 Correct 18 ms 3320 KB Output is correct
21 Correct 17 ms 3284 KB Output is correct
22 Correct 18 ms 3316 KB Output is correct
23 Correct 17 ms 3284 KB Output is correct
24 Correct 18 ms 3280 KB Output is correct
25 Correct 18 ms 3312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 7 ms 1364 KB Output is correct
30 Correct 13 ms 2388 KB Output is correct
31 Correct 23 ms 3432 KB Output is correct
32 Correct 20 ms 3444 KB Output is correct
33 Correct 20 ms 3412 KB Output is correct
34 Correct 20 ms 3412 KB Output is correct
35 Correct 20 ms 3412 KB Output is correct
36 Correct 26 ms 3436 KB Output is correct
37 Correct 20 ms 3444 KB Output is correct
38 Correct 19 ms 3412 KB Output is correct
39 Correct 20 ms 3320 KB Output is correct
40 Correct 20 ms 3440 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 320 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 6 ms 848 KB Output is correct
48 Correct 6 ms 980 KB Output is correct
49 Correct 12 ms 1496 KB Output is correct
50 Correct 21 ms 2668 KB Output is correct
51 Correct 31 ms 3880 KB Output is correct
52 Correct 31 ms 3796 KB Output is correct
53 Correct 32 ms 3868 KB Output is correct
54 Correct 31 ms 3884 KB Output is correct
55 Correct 32 ms 3824 KB Output is correct
56 Correct 35 ms 3828 KB Output is correct
57 Correct 32 ms 3812 KB Output is correct
58 Correct 31 ms 3788 KB Output is correct
59 Correct 31 ms 3824 KB Output is correct
60 Correct 31 ms 3796 KB Output is correct
61 Correct 31 ms 3876 KB Output is correct
62 Correct 31 ms 3796 KB Output is correct
63 Correct 32 ms 3828 KB Output is correct
64 Correct 31 ms 3888 KB Output is correct
65 Correct 30 ms 3788 KB Output is correct
66 Correct 31 ms 3896 KB Output is correct
67 Correct 31 ms 3820 KB Output is correct
68 Correct 32 ms 3812 KB Output is correct
69 Correct 30 ms 3796 KB Output is correct
70 Correct 31 ms 3796 KB Output is correct
71 Correct 8 ms 980 KB Output is correct
72 Correct 7 ms 1072 KB Output is correct
73 Correct 7 ms 980 KB Output is correct
74 Correct 6 ms 980 KB Output is correct
75 Correct 7 ms 1076 KB Output is correct
76 Correct 14 ms 1876 KB Output is correct
77 Correct 14 ms 1868 KB Output is correct
78 Correct 14 ms 1864 KB Output is correct
79 Correct 15 ms 1876 KB Output is correct
80 Correct 14 ms 1876 KB Output is correct
81 Correct 31 ms 3528 KB Output is correct
82 Correct 31 ms 3528 KB Output is correct
83 Correct 32 ms 3456 KB Output is correct
84 Correct 32 ms 3460 KB Output is correct
85 Correct 31 ms 3464 KB Output is correct
86 Correct 38 ms 4324 KB Output is correct
87 Correct 37 ms 4324 KB Output is correct
88 Correct 39 ms 4244 KB Output is correct
89 Correct 39 ms 4288 KB Output is correct
90 Correct 39 ms 4316 KB Output is correct
91 Correct 85 ms 11352 KB Output is correct
92 Correct 85 ms 11376 KB Output is correct
93 Correct 102 ms 11428 KB Output is correct
94 Correct 89 ms 11436 KB Output is correct
95 Correct 83 ms 11368 KB Output is correct
96 Correct 128 ms 18632 KB Output is correct
97 Correct 123 ms 18648 KB Output is correct
98 Correct 122 ms 18632 KB Output is correct
99 Correct 115 ms 18620 KB Output is correct
100 Correct 123 ms 18632 KB Output is correct
101 Correct 132 ms 18532 KB Output is correct
102 Correct 138 ms 18624 KB Output is correct
103 Correct 115 ms 18624 KB Output is correct
104 Correct 119 ms 18552 KB Output is correct
105 Correct 144 ms 18544 KB Output is correct
106 Correct 178 ms 22172 KB Output is correct
107 Correct 134 ms 22128 KB Output is correct
108 Correct 167 ms 22172 KB Output is correct
109 Correct 157 ms 22104 KB Output is correct
110 Correct 158 ms 22220 KB Output is correct
111 Correct 142 ms 22108 KB Output is correct
112 Correct 142 ms 22104 KB Output is correct
113 Correct 141 ms 22172 KB Output is correct
114 Correct 160 ms 22244 KB Output is correct
115 Correct 144 ms 22192 KB Output is correct
116 Incorrect 4700 ms 1476 KB Output isn't correct
117 Halted 0 ms 0 KB -