답안 #1062837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062837 2024-08-17T11:08:11 Z MrNanama 벽 (IOI14_wall) C++17
100 / 100
1728 ms 224648 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second

using namespace std;
using ll = long long;

template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec){for (auto itr : vec){os << itr << " ";} return os;}

vector<ll> arr;
vector<ll> seg;
vector<ll> lazy_set;
vector<ll> lazy_add;
vector<ll> lazy_rmv;

void pushdown(ll ind, ll l, ll r){
	if(l == r){return;}

	if(lazy_set[ind] != -1){
		lazy_set[2*ind] = lazy_set[ind];
		lazy_add[2*ind] = 0;
		lazy_rmv[2*ind] = LLONG_MAX;
	}else{
		if(lazy_set[2*ind] != -1){
			lazy_set[2*ind] = max<ll>(lazy_set[2*ind], lazy_add[ind]);
			lazy_set[2*ind] = min<ll>(lazy_set[2*ind], lazy_rmv[ind]);
		}else{
			if(lazy_add[ind] >= lazy_rmv[2*ind]){
				lazy_set[2*ind] = lazy_add[ind];
				lazy_add[2*ind] = 0;
				lazy_rmv[2*ind] = LLONG_MAX;
			}else if(lazy_rmv[ind] <= lazy_add[2*ind]){
				lazy_set[2*ind] = lazy_rmv[ind];
				lazy_add[2*ind] = 0;
				lazy_rmv[2*ind] = LLONG_MAX;
			}else{
				lazy_add[2*ind] = max<ll>(lazy_add[ind], lazy_add[2*ind]);
				lazy_rmv[2*ind] = min<ll>(lazy_rmv[ind], lazy_rmv[2*ind]);
			}
		}
	}

	if(lazy_set[ind] != -1){
		lazy_set[2*ind+1] = lazy_set[ind];
		lazy_add[2*ind+1] = 0;
		lazy_rmv[2*ind+1] = LLONG_MAX;
	}else{
		if(lazy_set[2*ind+1] != -1){
			lazy_set[2*ind+1] = max<ll>(lazy_set[2*ind+1], lazy_add[ind]);
			lazy_set[2*ind+1] = min<ll>(lazy_set[2*ind+1], lazy_rmv[ind]);
		}else{
			if(lazy_add[ind] >= lazy_rmv[2*ind+1]){
				lazy_set[2*ind+1] = lazy_add[ind];
				lazy_add[2*ind+1] = 0;
				lazy_rmv[2*ind+1] = LLONG_MAX;
			}else if(lazy_rmv[ind] <= lazy_add[2*ind+1]){
				lazy_set[2*ind+1] = lazy_rmv[ind];
				lazy_add[2*ind+1] = 0;
				lazy_rmv[2*ind+1] = LLONG_MAX;
			}else{
				lazy_add[2*ind+1] = max<ll>(lazy_add[ind], lazy_add[2*ind+1]);
				lazy_rmv[2*ind+1] = min<ll>(lazy_rmv[ind], lazy_rmv[2*ind+1]);
			}
		}
	}

	//clear all lazys
	lazy_set[ind] = -1;
	lazy_add[ind] = 0;
	lazy_rmv[ind] = LLONG_MAX;
}

void upd_add(ll ind, ll val, ll tl, ll tr, ll l, ll r){
	pushdown(ind, l, r);
	if(max<ll>(l,tl) > min<ll>(r,tr)){return;}

	if(tl <= l && r <= tr){
		if(lazy_set[ind] != -1){
			lazy_set[ind] = max<ll>(lazy_set[ind], val);
		}else if(lazy_rmv[ind] <= val){
			lazy_set[ind] = val;
			lazy_add[ind] = 0;
			lazy_rmv[ind] = LLONG_MAX;
		}else{
			lazy_add[ind] = max<ll>(lazy_add[ind], val);
		}
	}else{
		ll m = (r-l)/2+l;
		upd_add(2*ind, val, tl, tr, l, m);
		upd_add(2*ind+1, val, tl, tr, m+1, r);
	}

	pushdown(ind,l,r);
}

void upd_rmv(ll ind, ll val, ll tl, ll tr, ll l, ll r){
	pushdown(ind, l, r);
	if(max<ll>(l,tl) > min<ll>(r,tr)){return;}

	if(tl <= l && r <= tr){
		if(lazy_set[ind] != -1){
			lazy_set[ind] = min<ll>(lazy_set[ind], val);
		}else if(lazy_add[ind] >= val){
			lazy_set[ind] = val;
			lazy_add[ind] = 0;
			lazy_rmv[ind] = LLONG_MAX;
		}else{
			lazy_rmv[ind] = min<ll>(lazy_rmv[ind], val);
		}
	}else{
		ll m = (r-l)/2+l;
		upd_rmv(2*ind, val, tl, tr, l, m);
		upd_rmv(2*ind+1, val, tl, tr, m+1, r);
	}

	pushdown(ind,l,r);
}


void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
		
	lazy_set.assign(4*n, -1);
	lazy_add.assign(4*n, 0);
	lazy_rmv.assign(4*n, LLONG_MAX);


	for(ll i=0; i<k; i++){

		if(op[i] == 1){
			//adding
			upd_add(1,height[i],left[i],right[i],0,n-1);

		}else{
			//removing
			upd_rmv(1,height[i],left[i],right[i],0,n-1);
		}

		/*
		cout << i << endl;
		cout << lazy_set << endl;
		cout << lazy_add << endl;
		cout << lazy_rmv << endl;
		*/
	}


	function<ll(ll,ll,ll)> dfs;

	dfs = [&](ll ind, ll l, ll r){
		pushdown(ind, l, r);
		if(l != r){
			ll m = (r-l)/2+l;
			dfs(2*ind, l, m);
			dfs(2*ind+1, m+1, r);
		}else{
			if(lazy_set[ind] != -1){
				finalHeight[l] = lazy_set[ind];
			}else{
				finalHeight[l] = lazy_add[ind];
			}
		}

		return 0;
	};
	dfs(1, 0, n-1);

}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 516 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 6 ms 1368 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 124 ms 8028 KB Output is correct
3 Correct 196 ms 5500 KB Output is correct
4 Correct 598 ms 18184 KB Output is correct
5 Correct 335 ms 18884 KB Output is correct
6 Correct 380 ms 18516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 6 ms 1320 KB Output is correct
5 Correct 6 ms 1308 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 80 ms 8032 KB Output is correct
9 Correct 205 ms 5480 KB Output is correct
10 Correct 586 ms 18180 KB Output is correct
11 Correct 329 ms 18516 KB Output is correct
12 Correct 330 ms 18516 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 85 ms 8244 KB Output is correct
15 Correct 51 ms 2640 KB Output is correct
16 Correct 610 ms 18440 KB Output is correct
17 Correct 350 ms 27280 KB Output is correct
18 Correct 328 ms 27512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1372 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 89 ms 8192 KB Output is correct
9 Correct 211 ms 5456 KB Output is correct
10 Correct 630 ms 18132 KB Output is correct
11 Correct 348 ms 18520 KB Output is correct
12 Correct 340 ms 18560 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 83 ms 8052 KB Output is correct
15 Correct 30 ms 2644 KB Output is correct
16 Correct 587 ms 18260 KB Output is correct
17 Correct 350 ms 27460 KB Output is correct
18 Correct 327 ms 27472 KB Output is correct
19 Correct 965 ms 224632 KB Output is correct
20 Correct 866 ms 222004 KB Output is correct
21 Correct 934 ms 224648 KB Output is correct
22 Correct 888 ms 222032 KB Output is correct
23 Correct 1022 ms 222036 KB Output is correct
24 Correct 840 ms 222188 KB Output is correct
25 Correct 891 ms 221988 KB Output is correct
26 Correct 855 ms 224568 KB Output is correct
27 Correct 950 ms 224556 KB Output is correct
28 Correct 1728 ms 222032 KB Output is correct
29 Correct 861 ms 222084 KB Output is correct
30 Correct 926 ms 222032 KB Output is correct