Submission #1288229

#TimeUsernameProblemLanguageResultExecution timeMemory
1288229blackscreen1Wall (IOI14_wall)C++20
61 / 100
857 ms276856 KiB
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "wall.h"
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define ld long double
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define iloop_(m, h, g) for (auto i = m; i < h; i += g)
#define jloop_(m, h, g) for (auto j = m; j < h; j += g)
#define kloop_(m, h, g) for (auto k = m; k < h; k += g)
#define lloop_(m, h, g) for (auto l = m; l < h; l += g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct node {
	ll s, e, m, l1, l2;
	node *l, *r;
	node (ll S, ll E) {
		s = S, e = E, m = (S+E)>>1;
		l1 = 0, l2 = INF;
		if (s != e) {
			l = new node(s, m);
			r = new node(m+1, e);
		}
	}
	void prop() {
		if (s != e) {
			l->l2 = min(l->l2, l2);
			l->l1 = max(min(l->l1, l2), l1);
			r->l2 = min(r->l2, l2);
			r->l1 = max(min(r->l1, l2), l1);
			l1 = 0, l2 = INF;
		}
	}
	void upd1(ll S, ll E, ll V) {
		prop();
		if (s == S && e == E) {
			l1 = max(l1, V);
			return;
		}
		if (E <= m) l->upd1(S, E, V);
		else if (S > m) r->upd1(S, E, V);
		else l->upd1(S, m, V), r->upd1(m+1, E, V);
		l->prop();
		r->prop();
	}
	void upd2(ll S, ll E, ll V) {
		prop();
		if (s == S && e == E) {
			l2 = min(l2, V);
			l1 = min(l1, V);
			return;
		}
		if (E <= m) l->upd2(S, E, V);
		else if (S > m) r->upd2(S, E, V);
		else l->upd2(S, m, V), r->upd2(m+1, E, V);
		l->prop();
		r->prop();
	}
	ll qu(ll X) {
		prop();
		if (s == e) return l1;
		if (X <= m) return l->qu(X);
		return r->qu(X);
	}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	node root = node(0, n-1);
	iloop(0, k) {
		if (op[i] == 1) root.upd1(left[i], right[i], height[i]);
		else root.upd2(left[i], right[i], height[i]);
		//cout << i << endl;
		//iloop(0, n) cout << root.qu(i).first << " ";
		//cout << endl;
	}
	iloop(0, n) finalHeight[i] = root.qu(i);
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...