Submission #907488

# Submission time Handle Problem Language Result Execution time Memory
907488 2024-01-15T17:37:32 Z TranGiaHuy1508 Izbori (COCI22_izbori) C++17
110 / 110
1064 ms 18700 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

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

#define int long long

int n, threshold;
vector<int> v;

map<int, int> compress, mpcnt;

int solve_light(vector<int> &V){
	vector<int> CNT(n + 5);
	int res = 0;
	for (int l = 0; l < n; l++){
		int mx = 0;
		for (int r = l; r <= min(n - 1, l + threshold * 2); r++){
			if (V[r] >= 0) mx = max(mx, ++CNT[V[r]]);
			if (mx * 2 > (r - l + 1)){
				res++;
			}
		}
		for (int r = l; r <= min(n - 1, l + threshold * 2); r++){
			if (V[r] >= 0) CNT[V[r]]--;
		}
	}
	return res;
}

int solve_heavy(vector<int> &V){
	vector<int> dp(n * 2 + 5, 0), cnt(n * 2 + 5, 0);
	int res = 0;
	int pfx = n + 2; cnt[pfx]++;

	for (int i = 0; i < n; i++){
		pfx += V[i];
		cnt[pfx]++;
		dp[pfx] = dp[pfx - 1] + cnt[pfx - 1];
		res += dp[pfx];
	}

	return res;
}

void main_program(){
	cin >> n;
	v.resize(n);

	threshold = sqrt(n);

	for (int i = 0; i < n; i++){
		cin >> v[i];
		compress[v[i]] = 1;
	}

	int crr = 1;
	for (auto &[key, value]: compress) value = crr++;
	for (auto &key: v) key = compress[key];

	for (int i = 0; i < n; i++){
		mpcnt[v[i]]++;
	}

	int res = 0;
	for (auto [key, value]: mpcnt){
		if (value > threshold){
			vector<int> vec(n);
			for (int i = 0; i < n; i++) vec[i] = (v[i] == key) ? 1 : -1;
			res += solve_heavy(vec);
		}
	}

	int bruhbruh = -1;
	for (int i = 0; i < n; i++){
		if (mpcnt[v[i]] > threshold){
			v[i] = --bruhbruh;
		}
	}

	res += solve_light(v);

	cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 6676 KB Output is correct
2 Correct 224 ms 8536 KB Output is correct
3 Correct 100 ms 5208 KB Output is correct
4 Correct 228 ms 8848 KB Output is correct
5 Correct 257 ms 9308 KB Output is correct
6 Correct 264 ms 9816 KB Output is correct
7 Correct 273 ms 9816 KB Output is correct
8 Correct 261 ms 9828 KB Output is correct
9 Correct 276 ms 9820 KB Output is correct
10 Correct 270 ms 9816 KB Output is correct
11 Correct 256 ms 9716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 152 ms 6676 KB Output is correct
19 Correct 224 ms 8536 KB Output is correct
20 Correct 100 ms 5208 KB Output is correct
21 Correct 228 ms 8848 KB Output is correct
22 Correct 257 ms 9308 KB Output is correct
23 Correct 264 ms 9816 KB Output is correct
24 Correct 273 ms 9816 KB Output is correct
25 Correct 261 ms 9828 KB Output is correct
26 Correct 276 ms 9820 KB Output is correct
27 Correct 270 ms 9816 KB Output is correct
28 Correct 256 ms 9716 KB Output is correct
29 Correct 276 ms 9820 KB Output is correct
30 Correct 69 ms 5200 KB Output is correct
31 Correct 193 ms 9368 KB Output is correct
32 Correct 756 ms 18700 KB Output is correct
33 Correct 217 ms 10068 KB Output is correct
34 Correct 249 ms 10320 KB Output is correct
35 Correct 118 ms 7244 KB Output is correct
36 Correct 55 ms 4792 KB Output is correct
37 Correct 75 ms 5468 KB Output is correct
38 Correct 279 ms 9820 KB Output is correct
39 Correct 270 ms 9820 KB Output is correct
40 Correct 278 ms 11868 KB Output is correct
41 Correct 294 ms 9848 KB Output is correct
42 Correct 301 ms 9816 KB Output is correct
43 Correct 291 ms 9848 KB Output is correct
44 Correct 293 ms 9852 KB Output is correct
45 Correct 310 ms 9852 KB Output is correct
46 Correct 289 ms 9848 KB Output is correct
47 Correct 318 ms 11788 KB Output is correct
48 Correct 691 ms 10060 KB Output is correct
49 Correct 674 ms 10020 KB Output is correct
50 Correct 438 ms 9944 KB Output is correct
51 Correct 465 ms 10024 KB Output is correct
52 Correct 1064 ms 10260 KB Output is correct
53 Correct 970 ms 10132 KB Output is correct
54 Correct 695 ms 10028 KB Output is correct