There is a very long board with length L centimeter, L is a positive integer, so we can evenly divide the board into L segments, and they are labeled by 1, 2, … L from left to right, each is 1 centimeter long. Now we have to color the board - one segment with only one color. We can do following two operations on the board:
In our daily life, we have very few words to describe a color (red, green, blue, yellow…), so you may assume that the total number of different colors T is very small. To make it simple, we express the names of colors as color 1, color 2, … color T. At the beginning, the board was painted in color 1. Now the rest of problem is left to your.
更新时先将最底层的数据更新,然后再向上更新节点
#include
#include
#include
#include
#define maxn 100005
#define lson (root<<1)
#define rson (root<<1|1)
#define mid (l+r)>>1
using namespace std;
int n,m,tot;
char s[2];
int sum[maxn<<2],vis[maxn<<2];
void pushdown(int l,int r,int root)//向下更新
{
if(vis[root]!=-1) {
vis[lson]=vis[rson]=vis[root];
sum[lson]=sum[rson]=(1<m) {
update(m+1,r,rson,u,v,val);
}else {
update(l,m,lson,u,m,val);
update(m+1,r,rson,m+1,v,val);
}
pushup(l,r,root);//向上更新
}
int query(int l,int r,int root,int u,int v)
{
if(vis[root]!=-1){
return (1<m) {
res|=query(m+1,r,rson,u,v);
}else {
res|=query(l,m,lson,u,m);
res|=query(m+1,r,rson,m+1,v);
}
return res;
}
int main()
{
while(~scanf("%d%d%d",&n,&tot,&m))
{
memset(vis,-1,sizeof(vis));
memset(sum,0,sizeof(sum));
update(1,n,1,1,n,0);
while(m--)
{
int u,v,val;
scanf("%s%d%d",s,&u,&v);
u=min(u,v);
v=max(u,v);
if(s[0]=='C') {
scanf("%d",&val);
update(1,n,1,u,v,val-1);
}else {
int num=query(1,n,1,u,v),ans=0;
while(num)
{
if(num&1) ans++;
num>>=1;
}
printf("%d\n",ans);
}
}
}
return 0;
}