제출 #1313136

#제출 시각아이디문제언어결과실행 시간메모리
1313136nikaa123벽 (IOI14_wall)C++20
100 / 100
440 ms59144 KiB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;

const int inf = 1e9;
const int N = 2e6+5;

int mn[4200005];
int mx[4200005];

void applay(int node, int low, int up) {
  mn[node] = max(mn[node], low);
  mx[node] = max(mx[node], low);

  mx[node] = min(mx[node], up);
    mn[node] = min(mn[node], up);
}

void push(int node) {
  applay(node*2,mn[node],mx[node]);
  applay(node*2+1,mn[node],mx[node]);
  mn[node] = -inf;
  mx[node] = inf;
}

void update(int node, int l, int r, int L, int R, int h, int op) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    if (op == 1) applay(node,h,inf); else applay(node,0,h);
    return;
  }
  push(node);
  int mid = (l+r)/2;
  update(node*2,l,mid,L,R,h,op);
  update(node*2+1,mid+1,r,L,R,h,op);
}

void getans(int node, int l, int r,int finalheight[]) {
  if (l == r) {
    finalheight[l-1] = mn[node];
    return;
  }
  push(node);
  int mid = (l+r)/2;
  getans(node*2,l,mid,finalheight);
  getans(node*2+1,mid+1,r,finalheight);
  
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
  for (int i = 1; i <= 4200004; i++) {
    mx[i] = 1e9;
    mn[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    update(1,1,n,left[i]+1,right[i]+1,height[i],op[i]);
  }
  getans(1,1,n,finalHeight);
  return;
}

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