TMD有多组数据

# 2. 题解

#include <cstdio>
#include <algorithm>
#include <cctype>
#define LS(a) (a<<1)
#define RS(a) ((a<<1)|1)
using namespace std;
struct N{int l,r,d,f;N(){l=r=d=f=0;}}e[500000];
void update(int a){e[a].d=(e[LS(a)].d|e[RS(a)].d);}
void pdown(int a)
{
e[LS(a)].f=e[a].f,e[LS(a)].d=(1<<(e[a].f));
e[RS(a)].f=e[a].f,e[RS(a)].d=(1<<(e[a].f));
e[a].f=0;
}
void build(int l,int r,int a)
{
e[a].l=l,e[a].r=r,e[a].d=2;
if(l<r)build(l,(l+r)>>1,LS(a)),build(((l+r)>>1)+1,r,RS(a));
}
int query(int l,int r,int a)
{
if(l<=e[a].l&&e[a].r<=r)return e[a].d;
if(e[a].f)pdown(a);
int tot=0;
if(l<=((e[a].l+e[a].r)>>1))tot|=query(l,r,LS(a));
if(r>((e[a].l+e[a].r)>>1))tot|=query(l,r,RS(a));
}
void change(int l,int r,int k,int a)
{
if(l<=e[a].l&&e[a].r<=r){e[a].d=(1<<k),e[a].f=k;return;}
if(e[a].f)pdown(a);
if(l<=((e[a].l+e[a].r)>>1))change(l,r,k,LS(a));
if(r>((e[a].l+e[a].r)>>1))change(l,r,k,RS(a));
update(a);
}
int n,t,o;
int main()
{
while(~scanf("%d%d%d",&n,&t,&o))
{
build(1,n,1);
for(int i=1,a,b,c,d;i<=o;i++)
{
do a=getchar();while(!isalpha(a));
scanf("%d%d",&b,&c);
if(b>c)swap(b,c);
if(a>'C')printf("%d\n",cnt(query(b,c,1)));
else scanf("%d",&d),change(b,c,d,1);
}
}
return 0;
}