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 "wall.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e6+7, INF=1e9+7;
int ma[4*LIM], mi[4*LIM], N=1;
void spl(int v) {
ma[2*v]=min(ma[2*v], ma[v]);
ma[2*v]=max(ma[2*v], mi[v]);
ma[2*v+1]=min(ma[2*v+1], ma[v]);
ma[2*v+1]=max(ma[2*v+1], mi[v]);
mi[2*v]=max(mi[2*v], mi[v]);
mi[2*v]=min(mi[2*v], ma[v]);
mi[2*v+1]=max(mi[2*v+1], mi[v]);
mi[2*v+1]=min(mi[2*v+1], ma[v]);
ma[v]=INF;
mi[v]=-INF;
}
void maxuj(int v, int l, int r, int a, int b, int x) {
if(b<l || a>r) return;
if(a<=l && r<=b) {
ma[v]=max(ma[v], x);
mi[v]=max(mi[v], x);
return;
}
spl(v);
int mid=(l+r)/2;
maxuj(2*v, l, mid, a, b, x);
maxuj(2*v+1, mid+1, r, a, b, x);
}
void minuj(int v, int l, int r, int a, int b, int x) {
if(b<l || a>r) return;
if(a<=l && r<=b) {
ma[v]=min(ma[v], x);
mi[v]=min(mi[v], x);
return;
}
spl(v);
int mid=(l+r)/2;
minuj(2*v, l, mid, a, b, x);
minuj(2*v+1, mid+1, r, a, b, x);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
while(N<n) N*=2;
rep(i, N) {
ma[i]=INF;
mi[i]=-INF;
}
rep(i, k) {
if(op[i]==1) maxuj(1, 0, N-1, left[i], right[i], height[i]);
else minuj(1, 0, N-1, left[i], right[i], height[i]);
}
for(int i=1; i<N; ++i) spl(i);
rep(i, n) finalHeight[i]=ma[N+i];
}
# | 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... |