#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include "wall.h"
using namespace std;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define ll long long
#define ld long double
#define ui uint64_t
#define ar array
#define us unordered_set
#define cont(set, element) ((set).find(element) != (set).end())
/********* DEBUG *********/
template <typename T>
void outvec(const vector<T>& Z){
for (const T& x : Z)
cout << x << ' ';
cout << "\n";
}
void printVariable(const any& var) {
if (!var.has_value()) {
cout << "null";
return;
}
if (var.type() == typeid(int)) {
cout << any_cast<int>(var);
} else if (var.type() == typeid(double)) {
cout << any_cast<double>(var);
} else if (var.type() == typeid(float)) {
cout << any_cast<float>(var);
} else if (var.type() == typeid(char)) {
cout << any_cast<char>(var);
} else if (var.type() == typeid(bool)) {
cout << (any_cast<bool>(var) ? "true" : "false");
} else if (var.type() == typeid(string)) {
cout << any_cast<string>(var);
} else if (var.type() == typeid(const char*)) {
cout << any_cast<const char*>(var);
} else if (var.type() == typeid(long long)) {
cout << any_cast<long long>(var);
} else {
cout << "[unknown type]";
}
}
template<typename... Args>
void outval(Args... args) {
vector<any> variables = {args...};
for (size_t i = 0; i < variables.size(); ++i) {
printVariable(variables[i]);
if (i != variables.size() - 1) {
cout << " ";
}
}
cout << "\n";
}
#define nl "\n"
#define sp << " " <<
/********* DEBUG *********/
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1000000000;
const ll needMOD = 987654321;
const ll mxN = 2000001;
const ll inf = 1e18;
struct nd{
ll ub=0, lb=0, pushval=0;
void upd(ll val){
if (val == 0)
return;
if (val > 0){
lb = max(lb, val-1);
ub = max(ub, lb);
}
else{
ub = min(ub, ~val);
lb = min(lb, ub);
}
}
};
vector<nd> tree(8000000);
void push(ll node, ll start, ll end){
tree[node].upd(tree[node].pushval);
//outval("pushval,start,end,nd:",tree[node].pushval, start,end,node);
if (start != end){
tree[2*node+1].upd(tree[2*node+1].pushval);
tree[2*node+2].upd(tree[2*node+2].pushval);
tree[2*node+1].pushval = tree[node].pushval;
tree[2*node+2].pushval = tree[node].pushval;
}
tree[node].pushval = 0;
}
void upd(ll l, ll r, ll val, ll node, ll start, ll end){
if (tree[node].pushval)
push(node, start, end);
if (l > end || r < start)
return;
if (l <= start && end <= r){
//outval("updated,start,end:",start,end);
tree[node].pushval = val;
push(node, start, end);
return;
}
ll m = (start+end)/2;
upd(l,r,val,2*node+1,start,m);
upd(l,r,val,2*node+2,m+1,end);
}
nd query(ll idx, ll node, ll start, ll end){
if (tree[node].pushval)
push(node, start, end);
if (start == idx && end == idx){
//outval("found:",node);
return tree[node];
}
ll m = (start+end)/2;
if (idx <= m){
return query(idx, 2 * node + 1, start, m);
}
else{
return query(idx, 2 * node + 2, m+1, end);
}
return {0};
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
tree.resize(4*n);
for (int i = 0; i < k; i++){
upd(left[i], right[i], op[i] == 1 ? height[i]+1 : ~height[i], 0, 0, n-1);
}
for (int i = 0; i < n; i++){
finalHeight[i] = query(i,0,0,n-1).ub;
}
return;
}
# | 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... |