제출 #784013

#제출 시각아이디문제언어결과실행 시간메모리
784013acatmeowmeow벽 (IOI14_wall)C++11
100 / 100
977 ms215720 KiB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

struct node {
	pair<int, int> v = {-1e9, 1e9}, lazy = {-1e9, 1e9};		
	node* lef = nullptr, *rig = nullptr;

	pair<int, int> combine(pair<int, int>f, pair<int, int>se) {
		int a = max(f.first, se.first), b = min(f.second, se.second);
		if (b < a) {
			if (se.second < f.first) return pair<int, int>(se.second, se.second);
			else return pair<int, int>(se.first, se.first);
		} else {
			return pair<int, int>(a, b);
		}
	}

	void push() {
		if (!lef) lef = new node(), rig = new node();
		lef->v = combine(lef->v, lazy), rig->v = combine(rig->v, lazy);
		lef->lazy = combine(lef->lazy, lazy), rig->lazy = combine(rig->lazy, lazy);
		lazy = {-1e9, 1e9};
	}

	void update(int tl, int tr, int l, int r, pair<int, int>x) {
		if (l > r) return;
		else if (tl == l && tr == r) v = combine(v, x), lazy = combine(lazy, x);
		else {
			push();
			int tm = (tl + tr)/2;
			lef->update(tl, tm, l, min(tm, r), x);
			rig->update(tm + 1, tr, max(l, tm + 1), r, x);
		}
	}

	pair<int, int> query(int tl, int tr, int k) {
		if (tl == tr) return v;
		else {
			push();
			int tm = (tl + tr)/2;
			if (k <= tm) return lef->query(tl, tm, k);
			else return rig->query(tm + 1, tr, k);
		}
	}
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	node*root = new node();
	for (int i = 0; i < k; i++) {
		int type = op[i], l = left[i], r = right[i], h = height[i];
		if (type == 1) root->update(0, n - 1, l, r, {h, 1e9});
		else root->update(0, n - 1, l, r, {-1e9, h});
	}
	for (int i = 0; i < n; i++) {
		pair<int, int> ans = root->query(0, n - 1, i);
		finalHeight[i] = max(0, ans.first);
	}
}

/*int main()
{
  int n;
  int k;

  int i, j;  
  int status = 0;

	cin >> n >> k;

  int* op = (int*)calloc(sizeof(int), k);
  int* left = (int*)calloc(sizeof(int), k);
  int* right = (int*)calloc(sizeof(int), k);
  int* height = (int*)calloc(sizeof(int), k);
  int* finalHeight = (int*)calloc(sizeof(int), n);

  for (i = 0; i < k; i++){
	  cin >> op[i] >> left[i] >> right[i] >> height[i];
 //   status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
   // assert(status == 4);
  }

  buildWall(n, k, op, left, right, height, finalHeight);

  for (j = 0; j < n; j++)
    //printf("%d\n", finalHeight[j]);
	cout << finalHeight[j] << '\n';
  
  return 0;
}*/


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