Submission #895777

# Submission time Handle Problem Language Result Execution time Memory
895777 2023-12-30T19:56:59 Z Isam Izbori (COCI22_izbori) C++17
0 / 110
3000 ms 3164 KB
#include<bits/stdc++.h>
using namespace std;
constexpr int sz = 200005;
int tree[sz << 2];

inline void update(int l, int r, int node, int x, int val){
	if(l > x || r < x) return;
	if(l == r){
		tree[node] += val;
		return;
	}
	int mid = l + ((r - l) >> 1);
	update(l, mid, node << 1, x, val);
	update(mid + 1, r, node << 1 | 1, x, val);
	tree[node] = tree[node << 1] + tree[node << 1 | 1];
	return;
}


int get_ans(int l, int r, int node, int L, int R){
	if(l > R || r < L) return 0;
	if(l >= L && r <= R) return tree[node];
	int mid = l + ((r - l) >> 1);
	return get_ans(l, mid, node << 1, L, R) + get_ans(mid + 1, r, node << 1 | 1, L, R);
}

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N;
	cin >> N;
	vector<int> A(N);
	for(register int i = 0; i < N; ++i){
		cin >> A[i];
		if(A[i] == 2) update(1, N, 1, i + 1, 1);
	}
	int ans(0);
	for(register int i = 0; i < N; ++i){
		for(register int j = i; j < N; ++j){
			int that = get_ans(1, N, 1, i + 1, j + 1);
			that = max(that, (j - i + 1) - that);
			ans += ((that << 1) > (j - i + 1));
		}
	}
	cout << ans << '\n';
	
		
	
	
	
	
	
	/*
	2 2 1 2 3
	
	2;
	2;
	1;
	2;
	3;
	2 2;
	2 2 1;
	2 1 2;
	2 2 1 2;
	2 2 1 2 3;   	
	*/
	
	
	
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |  for(register int i = 0; i < N; ++i){
      |                   ^
Main.cpp:37:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |  for(register int i = 0; i < N; ++i){
      |                   ^
Main.cpp:38:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   38 |   for(register int j = i; j < N; ++j){
      |                    ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3018 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -