#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define compact(v) v.erase(unique(all(v)) , v.end())
#define pi pair<int , int>
#define vi vector<int>
#define eb emplace_back
#define FOR(i , l , r) for(int i = l; i <= r; ++ i)
#define FORD(i , l , r) for(int i = l; i >= r; -- i)
using namespace std;
typedef long long ll;
const int nd = 2e6 + 1 , INF = 1e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(1 , (int)2e9);
template<typename T> bool maximize(T &a, T b) {return (a < b) ? false , a = b : true;}
template<typename T> bool minimize(T &a, T b) {return (a > b) ? false , a = b : true;}
struct node{
int opmin = 0 , opmax = INF;
node(): opmin(0) , opmax(INF){}
void add(int h){
maximize(opmin , h);
maximize(opmax , h);
}
void split(int h){
minimize(opmin , h);
minimize(opmax , h);
}
} st[4 * nd];
void dow(int id){
st[id * 2].add(st[id].opmin);
st[id * 2].split(st[id].opmax);
st[id * 2 + 1].add(st[id].opmin);
st[id * 2 + 1].split(st[id].opmax);
st[id] = node();
}
void up(int id , int l , int r , int a , int b , int op , int h){
if(l > b || r < a) return;
if(a <= l && r <= b){
if(op == 1) st[id].add(h);
else st[id].split(h);
return;
}
dow(id);
int mid = (r + l) >> 1;
up(id * 2 , l , mid , a , b , op , h); up(id * 2 + 1 , mid + 1 , r , a , b , op , h);
}
int build(int id , int l , int r , int x){
if(l > x || r < x) return 0;
if(l == r){
return st[id].opmin;
}
int mid = (r + l) >> 1;
dow(id);
return max(build(id * 2 , l , mid , x) , build(id * 2 + 1 , mid + 1 , r , x));
}
void buildWall(int n, int q, int op[], int left[], int right[], int height[], int finalHeight[]){
FOR(i , 0 , q - 1){
up(1 , 1 , n , left[i] + 1 , right[i] + 1 , op[i] , height[i]);
}
FOR(i , 0 , n - 1){
finalHeight[i] = build(1 , 1 , n , i + 1);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |