Submission #1018774

# Submission time Handle Problem Language Result Execution time Memory
1018774 2024-07-10T09:39:20 Z vjudge1 Izbori (COCI22_izbori) C++17
40 / 110
67 ms 18020 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;

void solve1(int n) {
	vector <int> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	auto compress = [&](vector <int> &a) {
		vector <pair<int, int> > v(a.size());
		for(int i = 0; i < n; i++) {
			v[i] = {a[i], i};
		}
		sort(v.begin(), v.end());
		for(int i = 0, ind = 0; i < n; i++) {
			if(i and v[i].first != v[i - 1].first) ind++;
			a[v[i].second] = ind;
		}
	};
	compress(arr);
	int ans = 0;
	for(int l = 0; l < n; l++) {
		vector <int> cnt(n);
		int mx = 0;
		for(int r = l; r < n; r++) {
			cnt[arr[r]]++;
			mx = max(mx, cnt[arr[r]]);
			if(mx > (r - l + 1) / 2) ans++;
		}
	}
	cout << ans << "\n";
}

void solve2(int n) {
	vector <int> arr(n+1), pre(n+1);
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		if(arr[i] == 2) arr[i] = -1;
		pre[i] = arr[i] + pre[i-1];
	}
	int sub = 0;
	map <int, int> mp;
	for(int i = n; i > 0; i--) {
		mp[pre[i]]++;
		sub += mp[pre[i - 1]];
	}
	cout << n * (n + 1) / 2 - sub << "\n";
}

int32_t main(){
	fast
	int n;
	cin >> n;
	if(n <= 2000) solve1(n);
	else solve2(n);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 3 ms 504 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2396 KB Output is correct
2 Correct 14 ms 3532 KB Output is correct
3 Correct 6 ms 2140 KB Output is correct
4 Correct 12 ms 3672 KB Output is correct
5 Correct 12 ms 3676 KB Output is correct
6 Correct 13 ms 4016 KB Output is correct
7 Correct 13 ms 3932 KB Output is correct
8 Correct 13 ms 4188 KB Output is correct
9 Correct 12 ms 4184 KB Output is correct
10 Correct 12 ms 3932 KB Output is correct
11 Correct 60 ms 16496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 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 3 ms 504 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 8 ms 2396 KB Output is correct
19 Correct 14 ms 3532 KB Output is correct
20 Correct 6 ms 2140 KB Output is correct
21 Correct 12 ms 3672 KB Output is correct
22 Correct 12 ms 3676 KB Output is correct
23 Correct 13 ms 4016 KB Output is correct
24 Correct 13 ms 3932 KB Output is correct
25 Correct 13 ms 4188 KB Output is correct
26 Correct 12 ms 4184 KB Output is correct
27 Correct 12 ms 3932 KB Output is correct
28 Correct 60 ms 16496 KB Output is correct
29 Correct 67 ms 18020 KB Output is correct
30 Incorrect 10 ms 3676 KB Output isn't correct
31 Halted 0 ms 0 KB -