下的数据本地过了。
#include <bits/stdc++.h>
using namespace std;
int read() {
int res = 0;
bool f = true;
char ch = getchar();
for(; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-')
f = false;
for(; ch <= '9' && ch >= '0'; ch = getchar())
res = (res << 3) + (res << 1) + (ch ^ 48);
return f ? res : ~res + 1;
}
const int N = 1E5 + 100;
class SegmentTree {
private:
struct Node {
int l, r, dat, tag;
}st[N << 2];
void Upd(int p) {
st[p].dat = st[p<<1].dat | st[p<<1|1].dat;
}
void Spread(int p) {
if (st[p].tag) {
st[p<<1].dat = st[p<<1|1].dat = st[p].tag;
st[p<<1].tag = st[p<<1|1].tag = st[p].tag;
st[p].tag = 0;
}
}
public:
void Build(int p, int l, int r) {
st[p].l = l;
st[p].r = r;
if (l == r) {
st[p].dat = 1;
return;
}
int mid = (l + r) >> 1;
Build(p<<1, l, mid);
Build(p<<1|1, mid+1, r);
Upd(p);
}
void Cover(int p, int l, int r, int x) {
if (l <= st[p].l && st[p].r <= r) {
st[p].dat = x;
st[p].tag = x;
return;
}
Spread(p);
int mid = (st[p].l + st[p].r) >> 1;
if (l <= mid)
Cover(p<<1, l, r, x);
if (r > mid)
Cover(p<<1|1, l, r, x);
Upd(p);
}
int Ask(int p, int l, int r) {
if (l <= st[p].l && st[p].r <= r)
return st[p].dat;
Spread(p);
int mid = (st[p].l + st[p].r) >> 1, res = 0;
if (l <= mid)
res |= Ask(p<<1, l, r);
if (r > mid)
res |= Ask(p<<1|1, l, r);
return res;
}
}st;
int BitCount(int x) {
int res = 0;
while (x) {
res += x & 1;
x >>= 1;
}
return res;
}
signed main() {
#ifdef ____
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
int n = read(), t = read(), q = read();
st.Build(1, 1, n);
while (q --> 0) {
char opt = getchar();
int l = read(), r = read();
if (l > r)
swap(l, r);
if (opt == 'P')
printf("%lld\n", BitCount(st.Ask(1, l, r)));
else
st.Cover(1, l, r, 1 << (read() - 1));
}
return 0;
}