Submission #753845

# Submission time Handle Problem Language Result Execution time Memory
753845 2023-06-06T07:43:03 Z Trisanu_Das Izbori (COCI22_izbori) C++17
110 / 110
2532 ms 5612 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n; int arr[n];
	vector<int> d;
	for(int i = 0; i < n; i++){
		cin >> arr[i];	
		d.push_back(arr[i]);
	}
	sort(d.begin(), d.end());										
	d.resize(unique(d.begin(), d.end()) - d.begin());
	vector<int> allcnt(d.size(), 0);
	for(int i = 0; i < n;i ++){
		arr[i] = lower_bound(d.begin(),d.end(),arr[i])-d.begin();
		allcnt[arr[i]]++;
	}
	int B = sqrt(2 * n);
	int C = (B / 2);
	ll ans = 0;
	for(int i = 0; i < n; i++){
		int maxn = 0, maxstuff = -1;
		vector<int> cnt(d.size(),0);
		for(int j = i; j < i + B && j < n; j++){
			cnt[arr[j]]++;
			if(maxn < cnt[arr[j]]){
				maxn = cnt[arr[j]];
				maxstuff = arr[j];
			}
			if(2 * maxn > (j - i + 1) && allcnt[maxstuff] < C) ans++;
		}
	}
	vector<int> cnt(2 * n + 1, 0);
	for(int s = 0; s < d.size(); s++){
		if(allcnt[s] < C) continue;
		ll p = 0;
		int sum = 0;
		fill(cnt.begin(),cnt.end(),0);
		cnt[n] = 1;
		for(int i=0;i<n;i++){
			if(arr[i]==s){
				p+=cnt[(sum++)+n];
				cnt[sum+n]++;
			}else{
				p-=cnt[(--sum)+n];
				cnt[sum+n]++;
			}
			ans+=p;
		}
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int s = 0; s < d.size(); s++){
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 2788 KB Output is correct
2 Correct 497 ms 3528 KB Output is correct
3 Correct 221 ms 2196 KB Output is correct
4 Correct 520 ms 3640 KB Output is correct
5 Correct 575 ms 3708 KB Output is correct
6 Correct 604 ms 3944 KB Output is correct
7 Correct 624 ms 4088 KB Output is correct
8 Correct 632 ms 3944 KB Output is correct
9 Correct 626 ms 3936 KB Output is correct
10 Correct 608 ms 3956 KB Output is correct
11 Correct 467 ms 3944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 336 ms 2788 KB Output is correct
19 Correct 497 ms 3528 KB Output is correct
20 Correct 221 ms 2196 KB Output is correct
21 Correct 520 ms 3640 KB Output is correct
22 Correct 575 ms 3708 KB Output is correct
23 Correct 604 ms 3944 KB Output is correct
24 Correct 624 ms 4088 KB Output is correct
25 Correct 632 ms 3944 KB Output is correct
26 Correct 626 ms 3936 KB Output is correct
27 Correct 608 ms 3956 KB Output is correct
28 Correct 467 ms 3944 KB Output is correct
29 Correct 475 ms 5512 KB Output is correct
30 Correct 189 ms 1380 KB Output is correct
31 Correct 545 ms 2404 KB Output is correct
32 Correct 2532 ms 5336 KB Output is correct
33 Correct 610 ms 2640 KB Output is correct
34 Correct 671 ms 2708 KB Output is correct
35 Correct 311 ms 1868 KB Output is correct
36 Correct 129 ms 1276 KB Output is correct
37 Correct 179 ms 1432 KB Output is correct
38 Correct 658 ms 3944 KB Output is correct
39 Correct 654 ms 4040 KB Output is correct
40 Correct 647 ms 3936 KB Output is correct
41 Correct 630 ms 4036 KB Output is correct
42 Correct 659 ms 3936 KB Output is correct
43 Correct 584 ms 5612 KB Output is correct
44 Correct 585 ms 5424 KB Output is correct
45 Correct 556 ms 5520 KB Output is correct
46 Correct 571 ms 5448 KB Output is correct
47 Correct 566 ms 5528 KB Output is correct
48 Correct 621 ms 4316 KB Output is correct
49 Correct 620 ms 4236 KB Output is correct
50 Correct 529 ms 4196 KB Output is correct
51 Correct 518 ms 4116 KB Output is correct
52 Correct 781 ms 4424 KB Output is correct
53 Correct 746 ms 4280 KB Output is correct
54 Correct 595 ms 4268 KB Output is correct