1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define LS(dq) ((dq) << 1) #define RS(dq) (((dq) << 1) | 1) #define fa(dq) ((dq) >> 1)
#define MAXN (10000 + 5) using namespace std; struct nodex { int ls, rs, le, ri, maxz, lazy; nodex(): ls(0), rs(0), maxz(0), lazy(0) {} }bx[MAXN << 8]; struct nodey { int le, ri, lazy, rootdq, rootson; nodey(): lazy(0) {} }by[MAXN << 3]; int n, d, s; static int cnt = 0; inline int newnode(int le, int ri) { bx[++cnt].le = le, bx[cnt].ri = ri; return cnt; } void jsy(int dq, int le, int ri) { by[dq].le = le, by[dq].ri = ri; by[dq].rootdq = newnode(1, d); by[dq].rootson = newnode(1, d); if (le == ri) return ; int mi = (le + ri) >> 1; jsy(LS(dq), le, mi); jsy(RS(dq), mi + 1, ri); } int cxx(int dq, int le, int ri) { if (!dq) return 0; int re = bx[dq].lazy; if (bx[dq].le == le && bx[dq].ri == ri) return max(re, bx[dq].maxz); int mi = (bx[dq].le + bx[dq].ri) >> 1; if (le > mi) return max(re, cxx(bx[dq].rs, le, ri)); else if (ri <= mi) return max(re, cxx(bx[dq].ls, le, ri)); else return max(re, max(cxx(bx[dq].ls, le, mi), cxx(bx[dq].rs, mi + 1, ri))); } int cxy(int dq, int le, int ri, int lx, int rx) { int re = cxx(by[dq].rootdq, lx, rx); if (by[dq].le == le && by[dq].ri == ri) return max(re, cxx(by[dq].rootson, lx, rx)); int mi = (by[dq].le + by[dq].ri) >> 1; if (ri <= mi) return max(re, cxy(LS(dq), le, ri, lx, rx)); else if (le > mi) return max(re, cxy(RS(dq), le, ri, lx, rx)); else return max(re, max(cxy(LS(dq), le, mi, lx, rx), cxy(RS(dq), mi + 1, ri, lx, rx))); } void xgx(int& dq, int le, int ri, int zh, int dql, int dqr) { if (!dq) dq = newnode(dql, dqr); bx[dq].maxz = max(bx[dq].maxz, zh); if (dql == le && dqr == ri) { bx[dq].lazy = max(bx[dq].lazy, zh); return ; } int mi = (dql + dqr) >> 1; if (ri <= mi) xgx(bx[dq].ls, le, ri, zh, dql, mi); else if (le > mi) xgx(bx[dq].rs, le, ri, zh, mi + 1, dqr); else xgx(bx[dq].ls, le, mi, zh, dql, mi), xgx(bx[dq].rs, mi + 1, ri, zh, mi + 1, dqr); } void xgy(int dq, int le, int ri, int lx, int rx, int zh) {
xgx(by[dq].rootson, lx, rx, zh, 1, d); if (by[dq].le == le && by[dq].ri == ri) { xgx(by[dq].rootdq, lx, rx, zh, 1, d); return ; } int mi = (by[dq].le + by[dq].ri) >> 1; if (ri <= mi) xgy(LS(dq), le, ri, lx, rx, zh); else if (le > mi) xgy(RS(dq), le, ri, lx, rx, zh); else xgy(LS(dq), le, mi, lx, rx, zh), xgy(RS(dq), mi + 1, ri, lx, rx, zh); } int main() {
#ifndef DEBUG freopen("tet.in", "r", stdin); freopen("tet.out", "w", stdout); #endif scanf("%d%d%d", &d, &s, &n); jsy(1, 1, s); for (int i = 1; i <= n; i++) { int chang, kuan, gao, x, y, xx, yy; scanf("%d%d%d%d%d", &chang, &kuan, &gao, &x, &y); ++x, ++y; xx = x + chang, yy = y + kuan;
int maxh = cxy(1, y, yy - 1, x, xx - 1);
xgy(1, y, yy - 1, x, xx - 1, maxh + gao);
} printf("%d", cxy(1, 1, s - 1, 1, d - 1)); return 0; }
|