记录编号 |
601451 |
评测结果 |
AAAAAAAAAA |
题目名称 |
4149.色板游戏 |
最终得分 |
100 |
用户昵称 |
LikableP |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.471 s |
提交时间 |
2025-06-23 20:55:22 |
内存使用 |
3.68 MiB |
显示代码纯文本
#include <cstdio>
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
#define ls(root) root << 1
#define rs(root) root << 1 | 1
typedef unsigned long long ull;
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 {
ull color = 0;
ull lazy = 0;
} 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 = 1ull);
}
int mid = lt + ((rt - lt) >> 1);
Build(ls(root), lt, mid);
Build(rs(root), mid + 1, rt);
PushUp(root);
}
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)].color = 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, ull 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--) {
char op[5];
scanf("%s", op);
if (op[0] == 'C') {
int lq = read<int>(), rq = read<int>(), color = read<int>();
if (lq > rq)
lq ^= rq ^= lq ^= rq;
SeqPaint(1, 1, n, lq, rq, 1ull << (color - 1));
} else {
int lq = read<int>(), rq = read<int>();
if (lq > rq)
lq ^= rq ^= lq ^= rq;
write(__builtin_popcountll(GetSeq(1, 1, n, lq, rq)));
}
}
return 0;
}