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
|
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <vector>
#define DEBUG(x) std::cerr << #x << " = " << x << std::endl;
using std::cin; using std::cout; using std::endl;
inline int read() { int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
const int MAXN = 100000 + 10;
struct Node { int l, r, ls, rs, orr, tag; Node(int _l = 0, int _r = 0, int _ls = 0, int _rs = 0, int _orr = 0, int _tag = 0) { l = _l; r = _r; ls = _ls; rs = _rs; orr = _orr; tag = _tag; } } segt[MAXN << 2]; int cnt = 1;
int n, cols, q;
#define lson (segt[p].ls) #define rson (segt[p].rs)
void Update(int p) { segt[p].orr = segt[lson].orr | segt[rson].orr; }
void buildTree(int p, int l, int r) { segt[p] = Node(l, r); if (l == r) { segt[p].orr = 1; return; } int mid = (l + r) >> 1; buildTree(lson = ++cnt, l, mid); buildTree(rson = ++cnt, mid + 1, r); Update(p); }
void Cover(int p, int k) { segt[p].orr = segt[p].tag = k; }
void Pushdown(int p) { if (!segt[p].tag) return; Cover(lson, segt[p].tag); Cover(rson, segt[p].tag); segt[p].tag = 0; }
void Modify(int p, int l, int r, int k) { if (segt[p].l == l && segt[p].r == r) { Cover(p, k); return; } Pushdown(p); int mid = (segt[p].l + segt[p].r) >> 1; if (r <= mid) Modify(lson, l, r, k); else if (mid + 1 <= l) Modify(rson, l, r, k); else { Modify(lson, l, mid, k); Modify(rson, mid + 1, r, k); } Update(p); }
int Query(int p, int l, int r) { if (segt[p].l == l && r == segt[p].r) { return segt[p].orr; } Pushdown(p); int mid = (segt[p].l + segt[p].r) >> 1; if (r <= mid) return Query(lson, l, r); else if (mid + 1 <= l) return Query(rson, l, r); else return (Query(lson, l, mid) | Query(rson, mid + 1, r)); }
int popc(unsigned int n) { int count = 0; while (n) { ++count; n &= (n - 1); } return count; }
int main() { std::ios::sync_with_stdio(false); cin >> n >> cols >> q; buildTree(1, 1, n); for (int i = 1; i <= q; ++i) { char op; int a, b, c; cin >> op >> a >> b; if (a > b) std::swap(a, b); if (op == 'C') { cin >> c; Modify(1, a, b, (1 << (c - 1))); } else cout << popc(Query(1, a, b)) << endl; } return 0; }
|