Submission #1313126

#TimeUsernameProblemLanguageResultExecution timeMemory
1313126nikaa123벽 (IOI14_wall)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;

const int inf = INT_MAX;
const int N = 5e5+5;

int mn[4*N];
int mx[4*N];

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

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

void push(int node) {
  applay(node*2,mn[node],mx[node]);
  applay(node*2+1,mn[node],mx[node]);
  mn[node] = 0;
  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);
}

int getans(int node, int l, int r, int pos) {
  if (l == r) {
    return mx[node];
  }
  push(node);
  int mid = (l+r)/2;
  if (pos <= mid) {
    return getans(node*2,l,mid,pos);
  } else {
    return getans(node*2+1,mid+1,r,pos);
  }
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
  for (int i = 1; i <= 4*n; i++) {
    mx[i] = -inf;
    mn[i] = inf;
  }
  for (int i = 1; i <= k; i++) {
    update(1,1,n,left[i]+1,right[i]+1,height[i],op[i]);
  }
  for (int i = 1; i <= n; i++) {
    finalHeight[i-1] = getans(1,1,n,i);
  }
  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...