답안 #893748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893748 2023-12-27T10:49:36 Z vjudge1 Izbori (COCI22_izbori) C++11
40 / 110
3000 ms 15956 KB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e5 + 10;
const ll mod = 1e9 + 7;

ll um(ll a, ll b){
	return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll binpow(ll x, ll step){
	ll res = 1LL;
	while(step){
		if(step & 1) res = um(res, x);
		x = um(x, x);
		step /= 2;
	}
	return res;
}
struct segtree {
	ll sz;
	vector <ll> tree;
	void init(ll n){
		sz = 1;
		while(sz < n) sz *= 2;
		tree.assign(2 * sz - 1, 0LL);
	}
	void upd(ll i, ll v, ll x, ll lx, ll rx){
		if(rx - lx == 1){
			tree[x] += v;
			return;
		}
		ll mid = (rx + lx) / 2;
		if(i < mid) upd(i, v, 2 * x + 1, lx, mid);
		else upd(i, v, 2 * x + 2, mid, rx);
		tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);
	}
	void upd(ll i, ll v){
		upd(i, v, 0, 0, sz);
	}
};
ll arr[N], b[N];
ll ans, n, sz;
void overall(){
	segtree obj;
  	obj.init(sz);
  	for(ll i = 0; i < n; i++){
  		for(ll j = i; j < n; j++){
  			obj.upd(arr[j], 1);
  			if(obj.tree[0] > (j - i + 1) / 2) ans++;
  		}
  		for(ll j = i; j < n; j++){
  			obj.upd(arr[j], -1);
  		}
  	}
}
void subtask3(){
	map <ll, ll> mp;
	ll cur = 0, act = 0;
	ans = (1LL * (n * (n + 1))) / 2LL;
	for(ll i = 0; i < n; i++){
		if(arr[i] == 0) cur--;
		else cur++;
		mp[cur]++;
	}
	cur = 0;
	for(ll i = 0; i < n; i++){
		ans -= mp[act];
		if(arr[i] == 0){
			cur--;
			act--;
		}
		else{
			cur++;
			act++;
		}
		mp[cur]--;
	}
}
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	cin >> n;
  	for(ll i = 0; i < n; i++){
  		cin >> arr[i];
  		b[i] = arr[i];
  	}
  	sort(b, b + n);
  	sz = unique(b, b + n) - b;
  	for(ll i = 0; i < n; i++){
  		arr[i] = lower_bound(b, b + sz, arr[i]) - b;
  	}
  	if(sz <= 2){
  		subtask3();
  	} else overall();
  	cout << ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2400 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2400 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 22 ms 2392 KB Output is correct
8 Correct 1 ms 2472 KB Output is correct
9 Correct 31 ms 2396 KB Output is correct
10 Correct 41 ms 2644 KB Output is correct
11 Correct 33 ms 2528 KB Output is correct
12 Correct 33 ms 2648 KB Output is correct
13 Correct 32 ms 2396 KB Output is correct
14 Correct 46 ms 2396 KB Output is correct
15 Correct 40 ms 2396 KB Output is correct
16 Correct 33 ms 2508 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2904 KB Output is correct
2 Correct 23 ms 3420 KB Output is correct
3 Correct 11 ms 2652 KB Output is correct
4 Correct 30 ms 3464 KB Output is correct
5 Correct 20 ms 3420 KB Output is correct
6 Correct 25 ms 3420 KB Output is correct
7 Correct 22 ms 3672 KB Output is correct
8 Correct 22 ms 3612 KB Output is correct
9 Correct 22 ms 3420 KB Output is correct
10 Correct 31 ms 3616 KB Output is correct
11 Correct 74 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2400 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 22 ms 2392 KB Output is correct
8 Correct 1 ms 2472 KB Output is correct
9 Correct 31 ms 2396 KB Output is correct
10 Correct 41 ms 2644 KB Output is correct
11 Correct 33 ms 2528 KB Output is correct
12 Correct 33 ms 2648 KB Output is correct
13 Correct 32 ms 2396 KB Output is correct
14 Correct 46 ms 2396 KB Output is correct
15 Correct 40 ms 2396 KB Output is correct
16 Correct 33 ms 2508 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
18 Correct 15 ms 2904 KB Output is correct
19 Correct 23 ms 3420 KB Output is correct
20 Correct 11 ms 2652 KB Output is correct
21 Correct 30 ms 3464 KB Output is correct
22 Correct 20 ms 3420 KB Output is correct
23 Correct 25 ms 3420 KB Output is correct
24 Correct 22 ms 3672 KB Output is correct
25 Correct 22 ms 3612 KB Output is correct
26 Correct 22 ms 3420 KB Output is correct
27 Correct 31 ms 3616 KB Output is correct
28 Correct 74 ms 15956 KB Output is correct
29 Correct 83 ms 15904 KB Output is correct
30 Execution timed out 3038 ms 3676 KB Time limit exceeded
31 Halted 0 ms 0 KB -