C A B C 是更新 A-B段位颜色C;
P A B 是查询 A - B 有种多少颜色;
居然把题目看成A不可能小于B。。。。(是有多渣T T)
因为只有30种颜色所以用int型可以记录下;
代码学着HH巨巨的 地址
#include<stdio.h>
#include<string.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid (l+r)>>1
#define maxn 500000
int sum[maxn<<2],col[maxn<<2];
int num[34];
void pushup(int rt){//向上更新
sum[rt]=sum[rt<<1]|sum[rt<<1|1];
}
void pushdown(int rt){
if(col[rt]){//向下更新
col[rt<<1]=col[rt<<1|1]=col[rt];
sum[rt<<1]=sum[rt<<1|1]=sum[rt];
col[rt]=0;
}
}
void build(int l,int r,int rt)
{
sum[rt]=1;//初始为颜色1
if(l==r){
return;
}
int m=mid;
build(lson);
build(rson);
pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
sum[rt]=num[c];
col[rt]=num[c];
return;
}
pushdown(rt);
int m=mid;
if(L<=m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r){
return sum[rt];
}
pushdown(rt);
int m=mid;
int res=0;
if(L<=m) res=res|query(L,R,lson);
if(R>m) res=res|query(L,R,rson);
return res;
}
int main(){
int n,q,t;
memset(num,0,sizeof(num));
num[1]=1;
for(int i=2;i<=30;i++)//先储存每种颜色。。。
num[i]=num[i-1]<<1;
while(scanf("%d %d %d ",&n,&t,&q)!=EOF){
memset(sum,0,sizeof(sum));
memset(col,0,sizeof(col));
build(1,n,1);
while(q--)
{
char s[3];
scanf("%s",s);
int a,b,c;
scanf("%d%d",&a,&b);
if(a>b){//万恶之源
int x=a;
a=b;
b=x;
}
if(s[0]=='P')
{
int ans=0;
int x=query(a,b,1,n,1);
while(x)//统计颜色个数
{
if(x&1==1)
ans++;
x=x>>1;
}
printf("%d\n",ans);
}
else {
scanf("%d",&c);
update(a,b,c,1,n,1);
}
}
}
return 0;
}