题意:两个操作:c l r x   l到r之间的颜色变成x

q l r      询问l到r有多少种颜色

思路:记一个整数表示哪种颜色是否取了

这里真的是煞笔了,看到这一题第一直觉是异或,但是A^A=0,相同的肿么办..然后搜题解....反应了一个下午,发现有按位或这样神气的存在

        1|1=1
        1|0=1
        0|1=1
        0|0=0
代码
#include "stdio.h"
#include "string.h"
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#include "algorithm"
#define MAX 100010
using namespace std;
int sum[MAX<<],col[MAX<<];
void pushup(int rt)
{
sum[rt]=(sum[rt<<]|sum[rt<<|]);
}
void pushdown(int rt)
{
if(col[rt])
{
col[rt<<]=col[rt<<|]=col[rt];
sum[rt<<]=sum[rt<<|]=<<(col[rt]-);
col[rt]=;
}
}
void build(int l,int r,int rt)
{
col[rt]=;
if(l==r)
{
sum[rt]=;
return;
}
int m=(l+r)>>;
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)
{
col[rt]=c;
sum[rt]=<<(c-);
return;
}
pushdown(rt);
int m=(l+r)>>;
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 ans=;
int m=(l+r)>>;
if(L<=m)
ans=(ans|query(L,R,lson));
if(R>m)
ans=(ans|query(L,R,rson));
return ans;
}
int main()
{
int n,l,r,col,x;
int q;
char s[];
while(scanf("%d%d%d",&n,&col,&q)==)
{
build(,n,);
while(q--)
{
scanf("%s",s);
if(s[]=='C')
{
scanf("%d%d%d",&l,&r,&x);
if(l>r)
l^=r^=l^=r;
update(l,r,x,,n,);
}
else
{
scanf("%d%d",&l,&r);
if(l>r)
l^=r^=l^=r;
int temp=query(l,r,,n,);
int ans=;
while(temp)
{
if(temp&)
ans++;
temp/=;
}
printf("%d\n",ans);
}
}
}
return ;
}

poj 2777的更多相关文章

  1. POJ 2777 Count Color(线段树染色,二进制优化)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 Des ...

  2. poj 2777 Count Color(线段树区区+染色问题)

    题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查 ...

  3. POJ 2777 Count Color(段树)

    职务地址:id=2777">POJ 2777 我去.. 延迟标记写错了.标记到了叶子节点上.. . . 这根本就没延迟嘛.. .怪不得一直TLE... 这题就是利用二进制来标记颜色的种 ...

  4. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  5. POJ 2777——线段树Lazy的重要性

    POJ 2777 Count Color --线段树Lazy的重要性 原题 链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000 ...

  6. poj 2777 Count Color

    题目连接 http://poj.org/problem?id=2777 Count Color Description Chosen Problem Solving and Program desig ...

  7. poj 2777 Count Color(线段树 区间更新)

    题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...

  8. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

  9. poj 2777 Count Color(线段树)

    题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  10. POJ 2777 Count Color(线段树+位运算)

    题目链接:http://poj.org/problem?id=2777 Description Chosen Problem Solving and Program design as an opti ...

随机推荐

  1. Android--Retrofit+RxJava(二)

    1,现在响应式编程也是越来越多在项目中使用了,刚好上篇我们简单了介绍了一下Retrofit,那么我们来开始试着两个一起用吧,不过不了解RxJava的同学可以先去看一看这个文章(挺好的):http:// ...

  2. paper 113:Bhattacharyya distance

    在统计理论中,Bhattacharyya距离用来度量两个离散或连续概率分布的相似性.它与Bhattacharyya系数(Bhattacharyya coefficient)高度相关,后者是用来度量两个 ...

  3. asp.net MVC实现文章的上一篇下一篇

    由于这个东西的原理没有什么难的(只是实现的时候有少量的坑),故直接上代码以便查阅.另:本文给出的Action附送了点击量统计. public ActionResult SingleNews(int? ...

  4. Angularjs 中文版API v1.3.9 阅读

    http://www.angularjsapi.cn/#/bootstrap 2016.7.4 ng.function: 1.angular.bind(self,fn,args ); 2.angula ...

  5. 关于webservice大数据量传输时的压缩和解压缩

    当访问WebSerivice时,如果数据量很大,传输数据时就会很慢.为了提高速度,我们就会想到对数据进行压缩.首先我们来分析一下. 当在webserice中传输数据时,一般都采用Dataset进行数据 ...

  6. 通过Trainingkit对Azure有一个初步的了解

    学习Azure有一个非常不错的资料库Azure training kit. 这里面包含了很多Azure团队编写的实例代码,以及为初学Azure的开发人员准备的新手教学课程. 开发人员可以从http:/ ...

  7. runoob

    今天学习bootstrap的时候偶然发现http://www.runoob.com/ 这个网站不错,比w3cschool界面要好看,内容要丰富 比较适合新手学习,而且上面的内容比较丰富,不错.

  8. Linq join on 多条件

    var a = from m in DbContext.Set<T1>() join q in DbContext.Set<T2>() on new { m.ID, Phone ...

  9. 第三章 对象(JavaScript:语言精粹)

      对象是属性的容器,其中每个属性都有名字和值.   3.0. 概览:对象字面量 | 检索 | 更新 | 引用 | 原型 | 反射 | 枚举 | 删除 | 减少全局变量污染   3.1. 对象字面量 ...

  10. R----data.table包介绍学习

    相比dplyr包,data.table包能够更大程度地提高数据的处理速度,这里就简单介绍一下data.tale包的使用方法. data.table:用于快速处理大数据集的哦 数据的读取 data.ta ...