题意:两个操作: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. 原生js快速渲染dom节点

    function renderDom(str){ var _div = document.createElement('div'); _div.innerHTML = str; var dom_tem ...

  2. 开始跟踪Redis啦,开帖

    随着NoSql的流行,对这方面的产品开始关注起来,之前一直只是看看.从昨天开始决定把Redis的实现机制啃下来,毕竟代码量也就2W行. 每天花时间看看,记录下成果. here we go.

  3. JSON 格式说明

    一维json { "sn" : "CS20160918095444121640", "suitstypes_id" : "47&q ...

  4. centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)

     1.yum安装nginx 下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/7/noarch/RPMS/ngin ...

  5. sql2008 表名为全数字时查询报错

    今天遇到个很奇葩的问题,在写一个应用程序时需要查询表的数据,但是表名是全数字的,直接查询会报错,于是想到给111的表名加一对中括号:即——>select * from [111] 刚开始还是报错 ...

  6. CentOS的网络配置(终端环境)

    在虚拟机中安装了Server版的CentOS,用于做Hadoop相关的实验.Server版的CentOS默认是没有桌面环境的,eth0的网络默认也没有开启,需要我们手动启动网络. 关键配置说明 网络和 ...

  7. C#编写最小化时隐藏为任务栏图标的 Window appllication.

    1.设置WinForm窗体属性showinTask=false 2.加notifyicon控件notifyIcon1,为控件notifyIcon1的属性Icon添加一个icon图标. 3.添加窗体最小 ...

  8. HTML 方法

    姓名输入框:<input type="text" value="默认有值"/> 密码输入框:<input type="text&qu ...

  9. 《BI项目笔记》历年的初烟水分均值变化分析Cube的建立

    主要维度: 班组班次检测项质检日期(时间维度)加工客户加工类型收购类型生产线产地烟叶级别 主要指标:慢速测定_平均值快速测定_平均值红外测定_平均值ETL设计 需要抽取的维度表: 序号 表名 说明 备 ...

  10. sqlalchemy 优化count()……

    一.sqlalchemy 中的count() count()统计数据特别慢: session.query(cls).count()  8W 数据花费了近50s 但是在数据库中直接查询: select ...