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
| #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; const int N = 5e5 + 10; LL K, D; int n, m; struct Node { LL s, v, lv, rv; int l, r; } tr[N << 2]; void pushup(Node &x, Node l, Node r) { x.lv = max(l.lv, l.s + r.lv); x.rv = max(r.rv, r.s + l.rv); x.v = max(l.rv + r.lv, max(l.v, r.v)); x.s = l.s + r.s; } void build(int x, int l, int r) { tr[x].l = l; tr[x].r = r; if (l == r) { tr[x].s = tr[x].v = tr[x].lv = tr[x].rv = -K; return; } int mid = l + r >> 1; build(x << 1, l, mid); build(x << 1 | 1, mid + 1, r); pushup(tr[x], tr[x << 1], tr[x << 1 | 1]); } void modify(int x, int t, LL k) { if (tr[x].l == tr[x].r) { tr[x].s = tr[x].v = tr[x].lv = tr[x].rv += k; return; } int mid = tr[x].l + tr[x].r >> 1; if (t <= mid) modify(x << 1, t, k); else modify(x << 1 | 1, t, k); pushup(tr[x], tr[x << 1], tr[x << 1 | 1]); } Node query(int x, int l, int r) { if (tr[x].l >= l && tr[x].r <= r) return tr[x]; int mid = tr[x].l + tr[x].r >> 1; if (r <= mid) return query(x << 1, l, r); if (l > mid) return query(x << 1 | 1, l, r); Node res; pushup(res, query(x << 1, l, r), query(x << 1 | 1, l, r)); return res; } int main() { scanf("%d%d%lld%lld", &n, &m, &K, &D); build(1, 1, n); for (int r, x; m; m--) { scanf("%d%d", &r, &x); modify(1, r, x); if (tr[1].v <= D * K) puts("TAK"); else puts("NIE"); } return 0; }
|