区间染色什么的。。。
#include<map>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
const int MAXN = 100005;
int n,T,m;
struct node
{
int cnt,col;
}tree[MAXN<<2] = {0};
#define L(x) (x<<1)
#define R(x) ((x<<1)|1)
void pushdown(int x)
{
if(tree[x].col)
{
tree[L(x)].col = tree[L(x)].cnt = tree[x].col;
tree[R(x)].col = tree[R(x)].cnt = tree[x].col;
tree[x].col = 0;
}
}
void update(int x)
{
tree[x].cnt = tree[L(x)].cnt | tree[R(x)].cnt;
}
void color(int l,int r,int ll,int rr,int si,int col)
{
if(ll == l && rr == r)
tree[si].col = tree[si].cnt = col;
else
{
int mid = (ll+rr)>>1;
pushdown(si);
if(r<=mid) color(l,r,ll,mid,L(si),col);
else if(l>mid)color(l,r,mid+1,rr,R(si),col);
else
{
color(l,mid,ll,mid,L(si),col);
color(mid+1,r,mid+1,rr,R(si),col);
}
update(si);
}
}
int count(int l,int r,int ll,int rr,int si)
{
if(ll == l && rr == r)return tree[si].cnt;
else
{
int mid = (ll+rr)>>1;
pushdown(si);
if(r<=mid) return count(l,r,ll,mid,L(si));
else if(l>mid)return count(l,r,mid+1,rr,R(si));
else return count(l,mid,ll,mid,L(si)) | count(mid+1,r,mid+1,rr,R(si));
}
}
int fold(int x)
{
int ret = 0;
while(x){ret+=(x&1); x>>=1;}
return ret;
}
#undef L
#undef R
int main()
{
#ifndef ONLINE_JUDGE
freopen("poj2777.in","r",stdin);
freopen("poj2777.out","w",stdout);
#endif
scanf("%d%d%d",&n,&T,&m);
tree[1].col = tree[1].cnt = 1;
while(m--)
{
int a,b,c;
char ch[5] = {'\0'};
scanf("%s",ch);
scanf("%d%d",&a,&b);
if(a > b) std::swap(a,b);
switch(ch[0])
{
case 'C': scanf("%d",&c);
color(a,b,1,n,1,1<<(c-1));
break;
case 'P': printf("%d\n",fold(count(a,b,1,n,1)));
break;
}
}
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}