답안 #704068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704068 2023-03-01T13:43:04 Z willychan Izbori (COCI22_izbori) C++14
110 / 110
2429 ms 5080 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int n;



int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.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;
		int 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+5,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:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int s=0;s<d.size();s++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 328 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 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 2760 KB Output is correct
2 Correct 445 ms 3424 KB Output is correct
3 Correct 211 ms 2196 KB Output is correct
4 Correct 490 ms 3632 KB Output is correct
5 Correct 502 ms 3700 KB Output is correct
6 Correct 536 ms 3936 KB Output is correct
7 Correct 539 ms 4040 KB Output is correct
8 Correct 544 ms 3936 KB Output is correct
9 Correct 536 ms 3940 KB Output is correct
10 Correct 541 ms 3936 KB Output is correct
11 Correct 479 ms 4040 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 328 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 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 298 ms 2760 KB Output is correct
19 Correct 445 ms 3424 KB Output is correct
20 Correct 211 ms 2196 KB Output is correct
21 Correct 490 ms 3632 KB Output is correct
22 Correct 502 ms 3700 KB Output is correct
23 Correct 536 ms 3936 KB Output is correct
24 Correct 539 ms 4040 KB Output is correct
25 Correct 544 ms 3936 KB Output is correct
26 Correct 536 ms 3940 KB Output is correct
27 Correct 541 ms 3936 KB Output is correct
28 Correct 479 ms 4040 KB Output is correct
29 Correct 489 ms 4384 KB Output is correct
30 Correct 159 ms 1380 KB Output is correct
31 Correct 530 ms 2404 KB Output is correct
32 Correct 2429 ms 5080 KB Output is correct
33 Correct 611 ms 2640 KB Output is correct
34 Correct 702 ms 2708 KB Output is correct
35 Correct 301 ms 1864 KB Output is correct
36 Correct 123 ms 1288 KB Output is correct
37 Correct 179 ms 1432 KB Output is correct
38 Correct 559 ms 3940 KB Output is correct
39 Correct 569 ms 4072 KB Output is correct
40 Correct 562 ms 3936 KB Output is correct
41 Correct 564 ms 3936 KB Output is correct
42 Correct 570 ms 3912 KB Output is correct
43 Correct 534 ms 4436 KB Output is correct
44 Correct 542 ms 4384 KB Output is correct
45 Correct 538 ms 4388 KB Output is correct
46 Correct 541 ms 4356 KB Output is correct
47 Correct 549 ms 4296 KB Output is correct
48 Correct 552 ms 4228 KB Output is correct
49 Correct 600 ms 4248 KB Output is correct
50 Correct 521 ms 4044 KB Output is correct
51 Correct 503 ms 4144 KB Output is correct
52 Correct 756 ms 4316 KB Output is correct
53 Correct 671 ms 4320 KB Output is correct
54 Correct 573 ms 4260 KB Output is correct