#include "wall.h"
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 2e6+5;
pll segtree[4*sz];
void build(ll v, ll l, ll r)
{
if(l == r)
segtree[v] = {0, 0};
else
{
ll mid = (l + r) / 2;
build(2*v, l, mid);
build(2*v+1, mid+1, r);
segtree[v] = {-1, 0};
}
}
void push1(ll v, ll l, ll r)
{
if(l != r)
{
if(segtree[v].f >= segtree[2*v].s)
segtree[2*v] = {segtree[v].f, segtree[v].f};
else if(segtree[v].s <= segtree[2*v].f)
segtree[2*v] = {segtree[v].s, segtree[v].s};
else
segtree[2*v] = {max(segtree[v].f, segtree[2*v].f), min(segtree[v].s, segtree[2*v].s)};
if(segtree[v].f >= segtree[2*v+1].s)
segtree[2*v+1] = {segtree[v].f, segtree[v].f};
else if(segtree[v].s <= segtree[2*v+1].f)
segtree[2*v+1] = {segtree[v].s, segtree[v].s};
else
segtree[2*v+1] = {max(segtree[v].f, segtree[2*v+1].f), min(segtree[v].s, segtree[2*v+1].s)};
segtree[v] = {LLONG_MIN, LLONG_MAX};
}
}
void update1(ll v, ll l, ll r, ll tl, ll tr, ll val)
{
push1(v, l, r);
if(l > r || l > tr || r < tl)
return;
if(tl <= l && r <= tr)
{
if(l == r){
segtree[v] = {max(val, segtree[v].f), max(val, segtree[v].f)};
return;
}
segtree[v] = {val, LLONG_MAX};
push1(v, l, r);
return;
}
ll mid = (l + r) / 2;
update1(2*v, l, mid, tl, tr, val);
update1(2*v+1, mid+1, r, tl, tr, val);
}
void update2(ll v, ll l, ll r, ll tl, ll tr, ll val)
{
push1(v, l, r);
if(l > r || l > tr || r < tl)
return;
if(tl <= l && r <= tr)
{
if(l == r){
segtree[v] = {min(val, segtree[v].f), min(val, segtree[v].f)};
return;
}
segtree[v] = {LLONG_MIN, val};
push1(v, l, r);
return;
}
ll mid = (l + r) / 2;
update2(2*v, l, mid, tl, tr, val);
update2(2*v+1, mid+1, r, tl, tr, val);
}
pll findres(ll v, ll l, ll r, ll tl, ll tr)
{
if(l > r || l > tr || r < tl)
return {LLONG_MIN, LLONG_MAX};
push1(v, l, r);
if(tl <= l && r <= tr)
return segtree[v];
ll mid = (l + r) / 2;
pll lans = findres(2*v, l, mid, tl, tr);
pll rans = findres(2*v+1, mid+1, r, tl, tr);
return {max(lans.f, rans.f), 0};
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
build(1, 1, n);
for(int i = 0; i < k; i++)
{
if(op[i] == 1)
update1(1, 1, n, left[i]+1, right[i]+1, height[i]);
else
update2(1, 1, n, left[i]+1, right[i]+1, height[i]);
}
for(int i = 0; i < n; i++)
finalHeight[i] = findres(1, 1, n, i, i).f;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |