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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#include <bits/stdc++.h>
const int POOL_SIZE = 20 * 1024 * 1024;
char pool[POOL_SIZE];
void *operator new(size_t size) { static char *s = pool; char *t = s; s += size; return t; }
void operator delete(void *) {}
void operator delete(void *, size_t) {}
struct InputOutputStream { enum { SIZE = 1024 * 1024 }; char ibuf[SIZE], *s, *t, obuf[SIZE], *oh;
InputOutputStream() : s(), t(), oh(obuf) {} ~InputOutputStream() { fwrite(obuf, 1, oh - obuf, stdout); }
inline char read() { if (s == t) t = (s = ibuf) + fread(ibuf, 1, SIZE, stdin); return s == t ? -1 : *s++; }
template <typename T> inline InputOutputStream &operator>>(T &x) { static char c; static bool iosig; for (c = read(), iosig = false; !isdigit(c); c = read()) { if (c == -1) return *this; iosig |= c == '-'; } for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0'); if (iosig) x = -x; return *this; }
inline void print(char c) { if (oh == obuf + SIZE) { fwrite(obuf, 1, SIZE, stdout); oh = obuf; } *oh++ = c; }
template <typename T> inline void print(T x) { static int buf[21], cnt; if (x != 0) { if (x < 0) { print('-'); x = -x; } for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 | 48; while (cnt) print((char)buf[cnt--]); } else { print('0'); } }
template <typename T> inline InputOutputStream &operator<<(const T &x) { print(x); return *this; } } io;
const int MAXN = 250000 + 9;
int n, m;
struct BinaryIndexedTree { int d[MAXN], n;
inline void add(int k, int v) { for (; k <= n; k += k & -k) d[k] += v; }
inline void modify(int l, int r, int v) { add(l, v); add(r + 1, -v); }
inline int query(int k) { int ret = 0; for (; k; k ^= k & -k) ret += d[k]; return ret; } } d;
std::map<int, int> range[MAXN];
inline void add(std::map<int, int> &map, int l, int r) { auto it = map.lower_bound(l); if (it != map.begin()) { --it; if (it->second >= r) return; if (it->second >= l) { l = it->first; d.modify(it->first, it->second, -1); map.erase(it); } } it = map.lower_bound(l); while (it != map.end() && it->first <= r) { r = std::max(it->second, r); d.modify(it->first, it->second, -1); it = map.erase(it); } map.insert(it, {l, r}); d.modify(l, r, 1); }
int main() { io >> n >> m; d.n = n; for (int cmd, l, r, v; m--;) { io >> cmd; switch (cmd) { case 0: { io >> l >> r >> v; add(range[v], l, r); break; } case 1: { io >> l; io << d.query(l) << '\n'; break; } } } return 0; }
|