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 <stdio.h>
#define N 2000000
#define N_ (1 << 21) /* N_ = pow2(ceil(log2(N))) */
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int aa[N_ * 2], bb[N_ * 2], lza[N_], lzb[N_], h_, n_;
void apply(int *a, int *b, int a_, int b_) {
*a = min(max(*a, a_), b_), *b = min(max(*b, a_), b_);
}
void put(int i, int a, int b) {
apply(&aa[i], &bb[i], a, b);
if (i < n_)
apply(&lza[i], &lzb[i], a, b);
}
void pus(int i) {
if (lza[i] != 0 || lzb[i] != INF) {
put(i << 1 | 0, lza[i], lzb[i]), put(i << 1 | 1, lza[i], lzb[i]);
lza[i] = 0, lzb[i] = INF;
}
}
void push(int i) {
int h;
for (h = h_; h > 0; h--)
pus(i >> h);
}
void update(int l, int r, int a, int b) {
int l_ = l += n_, r_ = r += n_;
push(l_), push(r_);
for ( ; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1)
put(l++, a, b);
if ((r & 1) == 0)
put(r--, a, b);
}
}
void buildWall(int n, int q, int *tt, int *ll, int *rr, int *height, int *ans) {
int h, i;
h_ = 0;
while (1 << h_ < n)
h_++;
n_ = 1 << h_;
for (i = 0; i < n_; i++)
lza[i] = 0, lzb[i] = INF;
for (h = 0; h < q; h++)
if (tt[h] == 1)
update(ll[h], rr[h], height[h], INF);
else
update(ll[h], rr[h], 0, height[h]);
for (i = 0; i < n_; i++)
pus(i);
for (i = 0; i < n; i++)
ans[i] = aa[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... |