比赛 2025.6.21 评测结果 MMMMMEEEEE
题目名称 色板游戏 最终得分 0
用户昵称 LikableP 运行时间 1.295 s
代码语言 C++ 内存使用 2.21 MiB
提交时间 2025-06-21 16:52:57
显示代码纯文本
#include <cstdio>
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
#define ls(root) root << 1
#define rs(root) root << 1 | 1

namespace IO {
template <typename T> T read() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    res = (res << 3) + (res << 1) + (ch ^ 48);
  return res * f;
}

template <typename T> void write(T x, char ed = '\n') {
  if (x < 0)
    putchar('-'), x = -x;
  static int sta[sizeof(T) << 2], top = 0;
  do {
    sta[++top] = x % 10;
    x /= 10;
  } while (x);
  while (top) {
    putchar(sta[top--] ^ 48);
  }
  putchar(ed);
}
} // namespace IO
using namespace IO;

const int MAXN = 1e5 + 10;

struct NODE {
  int color;
  int lazy;
} node[MAXN << 2];

void PushUp(int root) {
  node[root].color = node[ls(root)].color | node[rs(root)].color;
}

void Build(int root, int lt, int rt) {
  if (lt == rt) {
    return (void)(node[root].color = 1);
  }
  int mid = lt + ((rt - lt) >> 1);
  Build(ls(root), lt, mid);
  Build(rs(root), mid + 1, rt);
}

void PushDown(int root) {
  if (node[root].lazy) {
    node[ls(root)].color = node[root].lazy;
    node[ls(root)].lazy = node[root].lazy;
    node[rs(root)].lazy = node[root].lazy;
    node[rs(root)].lazy = node[root].lazy;
    node[root].lazy = 0;
  }
}

void SeqPaint(int root, int lt, int rt, int lq, int rq, int color) {
  if (lt == lq && rt == rq) {
    node[root].color = color;
    node[root].lazy = color;
    return;
  }
  PushDown(root);
  int mid = lt + ((rt - lt) >> 1);
  if (rq <= mid) {
    SeqPaint(ls(root), lt, mid, lq, rq, color);
  } else if (lq > mid) {
    SeqPaint(rs(root), mid + 1, rt, lq, rq, color);
  } else {
    SeqPaint(ls(root), lt, mid, lq, mid, color);
    SeqPaint(rs(root), mid + 1, rt, mid + 1, rq, color);
  }
  PushUp(root);
}

int GetSeq(int root, int lt, int rt, int lq, int rq) {
  if (lt == lq && rt == rq) {
    return node[root].color;
  }
  PushDown(root);
  int mid = lt + ((rt - lt) >> 1);
  if (rq <= mid) {
    return GetSeq(ls(root), lt, mid, lq, rq);
  } else if (lq > mid) {
    return GetSeq(rs(root), mid + 1, rt, lq, rq);
  } else {
    return GetSeq(ls(root), lt, mid, lq, mid) |
           GetSeq(rs(root), mid + 1, rt, mid + 1, rq);
  }
}

int n, q;

int main() {
  freopen("color.in", "r", stdin);
  freopen("color.out", "w", stdout);
  n = read<int>(), read<int>(), q = read<int>();
  Build(1, 1, n);
  while (q--) {
    for (char ch = getchar(); ch != '\n'; ch = getchar())
      ; // 读取结尾多余空格
    char op = getchar();
    if (op == 'C') {
      int lq = read<int>(), rq = read<int>(), color = read<int>();
      SeqPaint(1, 1, n, lq, rq, 1 << (color - 1));
    } else {
      int lq = read<int>(), rq = read<int>();
      write(__builtin_popcount(GetSeq(1, 1, n, lq, rq)));
    }
  }
  return 0;
}