답안 #696660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696660 2023-02-07T03:05:51 Z TranGiaHuy1508 Izbori (COCI22_izbori) C++17
110 / 110
912 ms 8016 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

const int maxn = 6e5 + 5;
int THRESHOLD;
int n;
int a[maxn], heavy[maxn];
int _dp[maxn * 2];
map<int, int> cmp;

void main_program(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		cmp[a[i]] = 1;
	}
	int CL = 0; for (auto &[key, value]: cmp) value = CL++;
	for (int i = 0; i < n; i++) a[i] = cmp[a[i]];

	THRESHOLD = 316;

	for (int i = 0; i < n; i++) heavy[a[i]]++;
	for (int i = 0; i < n; i++) heavy[i] = (heavy[i] > THRESHOLD);

	int* dp = _dp + maxn;
	long long res = 0;

	// Light
	for (int i = 0; i < n; i++){
		int mx = 0;
		for (int j = 0; j < THRESHOLD * 2 + 2; j++){
			if (i + j >= n) break;
			if (!heavy[a[i+j]]){
				dp[a[i+j]]++;
				mx = max(mx, dp[a[i+j]]);
			}
			if ((mx << 1) > (j+1)) res++;
		}
		for (int j = 0; j < THRESHOLD * 2 + 2; j++){
			if (i + j >= n) break;
			if (!heavy[a[i+j]]){
				dp[a[i+j]]--;
			}
		}
	}

	// Heavy
	for (int i = 0; i < n; i++){
		if (!heavy[i]) continue;
		long long less = 0, crr = 0;
		dp[crr]++;

		for (int j = 0; j < n; j++){
			int val = (a[j] == i) ? 1 : -1;
			if (val == 1){
				less += dp[crr];
				crr++;
			}
			else{
				crr--;
				less -= dp[crr];
			}
			dp[crr]++;

			res += less;
		}

		crr = 0; dp[crr]--;
		for (int j = 0; j < n; j++){
			int val = (a[j] == i) ? 1 : -1;
			crr += val;
			dp[crr]--;
		}
	}

	cout << res << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 7 ms 372 KB Output is correct
10 Correct 7 ms 340 KB Output is correct
11 Correct 7 ms 364 KB Output is correct
12 Correct 7 ms 340 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 7 ms 368 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 1364 KB Output is correct
2 Correct 235 ms 1676 KB Output is correct
3 Correct 139 ms 1124 KB Output is correct
4 Correct 243 ms 1672 KB Output is correct
5 Correct 250 ms 1808 KB Output is correct
6 Correct 278 ms 1884 KB Output is correct
7 Correct 267 ms 1892 KB Output is correct
8 Correct 283 ms 1876 KB Output is correct
9 Correct 266 ms 1880 KB Output is correct
10 Correct 266 ms 1996 KB Output is correct
11 Correct 262 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 7 ms 372 KB Output is correct
10 Correct 7 ms 340 KB Output is correct
11 Correct 7 ms 364 KB Output is correct
12 Correct 7 ms 340 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 7 ms 368 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 178 ms 1364 KB Output is correct
19 Correct 235 ms 1676 KB Output is correct
20 Correct 139 ms 1124 KB Output is correct
21 Correct 243 ms 1672 KB Output is correct
22 Correct 250 ms 1808 KB Output is correct
23 Correct 278 ms 1884 KB Output is correct
24 Correct 267 ms 1892 KB Output is correct
25 Correct 283 ms 1876 KB Output is correct
26 Correct 266 ms 1880 KB Output is correct
27 Correct 266 ms 1996 KB Output is correct
28 Correct 262 ms 2652 KB Output is correct
29 Correct 279 ms 2664 KB Output is correct
30 Correct 182 ms 2388 KB Output is correct
31 Correct 372 ms 4244 KB Output is correct
32 Correct 912 ms 8016 KB Output is correct
33 Correct 382 ms 4376 KB Output is correct
34 Correct 400 ms 4568 KB Output is correct
35 Correct 257 ms 3224 KB Output is correct
36 Correct 153 ms 2132 KB Output is correct
37 Correct 185 ms 2516 KB Output is correct
38 Correct 274 ms 2268 KB Output is correct
39 Correct 273 ms 2272 KB Output is correct
40 Correct 279 ms 2268 KB Output is correct
41 Correct 277 ms 2264 KB Output is correct
42 Correct 270 ms 2280 KB Output is correct
43 Correct 293 ms 2524 KB Output is correct
44 Correct 290 ms 2520 KB Output is correct
45 Correct 302 ms 2636 KB Output is correct
46 Correct 288 ms 2520 KB Output is correct
47 Correct 287 ms 2536 KB Output is correct
48 Correct 490 ms 2656 KB Output is correct
49 Correct 479 ms 2788 KB Output is correct
50 Correct 369 ms 2636 KB Output is correct
51 Correct 350 ms 2672 KB Output is correct
52 Correct 673 ms 2812 KB Output is correct
53 Correct 648 ms 2636 KB Output is correct
54 Correct 474 ms 2752 KB Output is correct