## Algorithm design

## Sample code

` `#include
#include
#include
const int N = 110000, L = 110000, INF = 0x7fffffff;
int n;
struct a_d {
int h, l, r, v;
int ld, rd; // left down to
} a[N];
inline bool cmp(a_d a, a_d b) {
return a.h < b.h;
}
struct node {
int l, r;
int f;
node *lc, *rc;
} mem[2 * L];
node *memp;
node *root;
node *init(int l, int r) {
node *p = memp++;
p->l = l;
p->r = r;
p->f = 0;
if (l == r) {
p->lc = p->rc = NULL;
} else {
int mid = (l + r) >> 1;
p->lc = init(l, mid);
p->rc = init(mid + 1, r);
}
return p;
}
inline void push_down(node *p) {
if (p->f) {
p->lc->f = p->f;
p->rc->f = p->f;
p->f = 0;
}
}
void change(node *p, int l, int r, int f) {
if (l <= p->l && p->r <= r) {
p->f = f;
return;
}
push_down(p);
int mid = (p->l + p->r) >> 1;
if (l <= mid) change(p->lc, l, r, f);
if (mid < r) change(p->rc, l, r, f);
}
int query(node *p, int i) {
if (i == p->l && p->r == i) {
return p->f;
}
push_down(p);
int mid = (p->l + p->r) >> 1;
if (i <= mid) return query(p->lc, i);
return query(p->rc, i);
}
int d[N];
inline int max(int a, int b) {
if (a > b) return a; else return b;
}
int main() {
// freopen("input.txt", "r", stdin);
while(scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; ++i) scanf("%d%d%d%d", &a[i].h, &a[i].l, &a[i].r, &a[i].v);
a[0].v = 0;
std::sort(a + 1, a + n + 1, cmp);
//
// for (int i = 1; i <= n; ++i) printf("%d %d %d\n", i, a[i].l, a[i].r); printf("\n");
memp = mem;
root = init(0, 100010);
for (int i = 1; i <= n; ++i) {
// printf("%d %d %d\n", i, a[i].l, a[i].r);
a[i].ld = query(root, a[i].l); // 注意这里不 +1 -1
a[i].rd = query(root, a[i].r);
change(root, a[i].l, a[i].r, i);
}
//
// for (int i = 1; i <= n; ++i) printf("%d %d %d\n", i, a[i].ld, a[i].r D);
for (int i = 0; I < = n; ++i) d[i] = -INF;
d[n] = 100 + a[n].v; -INF (= =; (int) = (0)); (= = ((), + +); = = (=, (+, + +)); ((0)} ("" ",") ";"