This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
#define mp make_pair
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()
const int N = 2*100005;
const long long MOD = 1e9+7;
const long double EPS = 0.000000001;
const double PI = 3.14159265358979323846;
const int nx[4]={1, -1, 0, 0}, ny[4]={0, 0, 1, -1};
long long gcd(int a, int b) { return (b==0?a:gcd(b, a%b)); }
long long lcm(int a, int b) { return a*(b/gcd(a, b)); }
long long fact(int a) { return (a==1?1:a*fact(a-1)); }
ll st[4*200005], lazy[4*200005], p[4*200005];
void prop(ll v, ll l, ll r) {
if(l==r||p[v]==-1) return;
if(p[v]==1) {
if(p[v*2]==-1||p[v*2]==2) lazy[v*2]=lazy[v];
else lazy[v*2]=max(lazy[v*2], lazy[v]);
p[v*2]=1; st[v*2]=max(st[v*2], lazy[v*2]);
if(p[v*2+1]==-1||p[v*2+1]==2) lazy[v*2+1]=lazy[v];
else lazy[v*2+1]=max(lazy[v*2+1], lazy[v]);
p[v*2+1]=1; st[v*2+1]=max(st[v*2+1], lazy[v*2+1]);
}
else if(p[v]==2) {
if(p[v*2]==-1||p[v*2]==1) lazy[v*2]=lazy[v];
else lazy[v*2]=min(lazy[v*2], lazy[v]);
p[v*2]=2; st[v*2]=min(st[v*2], lazy[v*2]);
if(p[v*2+1]==-1||p[v*2+1]==1) lazy[v*2+1]=lazy[v];
else lazy[v*2+1]=min(lazy[v*2+1], lazy[v]);
p[v*2+1]=2; st[v*2+1]=min(st[v*2+1], lazy[v*2+1]);
}
p[v]=-1;
}
void update0(ll v, ll l, ll r, ll lo, ll hi, ll val) {
prop(v, l, r);
if(l>hi||r<lo) return;
if(l>=lo&&r<=hi) {
if(p[v]==-1||p[v]==2) lazy[v]=val;
else lazy[v]=max(lazy[v], val);
p[v]=1; st[v]=max(st[v], lazy[v]);
prop(v, l, r);
return;
}
update0(v*2, l, (l+r)/2, lo, hi, val);
update0(v*2+1, (l+r)/2+1, r, lo, hi, val);
}
void update(ll v, ll l, ll r, ll lo, ll hi, ll val) {
prop(v, l, r);
if(l>hi||r<lo) return;
if(l>=lo&&r<=hi) {
if(p[v]==-1||p[v]==1) lazy[v]=val;
else lazy[v]=min(lazy[v], val);
p[v]=2; st[v]=min(st[v], lazy[v]);
prop(v, l, r);
return;
}
update(v*2, l, (l+r)/2, lo, hi, val);
update(v*2+1, (l+r)/2+1, r, lo, hi, val);
}
ll query(ll v, ll l, ll r, ll ind) {
prop(v, l, r);
if(l==r) return st[v];
ll mid=(l+r)/2;
if(ind<=mid) return query(v*2, l, mid, ind);
else return query(v*2+1, mid+1, r, ind);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
memset(p, -1, sizeof p);
for(ll l=0;l<k;l++) {
ll t=op[l], a=left[l], b=right[l], w=height[l];
if(t==1) update0(1, 0, n-1, a, b, w);
else if(t==2) update(1, 0, n-1, a, b, w);
}
for(ll l=0;l<n;l++) finalHeight[l]=query(1, 0, n-1, l);
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... |