职务地址:

id=2777">POJ 2777

我去。。

延迟标记写错了。标记到了叶子节点上。。

这根本就没延迟嘛。。

。怪不得一直TLE。。。

这题就是利用二进制来标记颜色的种类。然后利用或|这个符号来统计每一个区间不同颜色种数。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
int sum[410000];
int lazy[410000];
int pow1[40];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]|sum[rt<<1|1];
}
void PushDown(int rt)
{
if(lazy[rt])
{
lazy[rt<<1]=lazy[rt];
lazy[rt<<1|1]=lazy[rt];
sum[rt<<1]=lazy[rt];
sum[rt<<1|1]=lazy[rt];
lazy[rt]=0;
}
}
void update(int ll, int rr, int c, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
sum[rt]=c;
lazy[rt]=c;
return ;
}
PushDown(rt);
int mid=l+r>>1;
if(ll<=mid) update(ll,rr,c,lson);
if(rr>mid) update(ll,rr,c,rson);
PushUp(rt);
}
int query(int ll, int rr, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
return sum[rt];
}
PushDown(rt);
int ans=0;
int mid=l+r>>1;
if(ll<=mid) ans=ans|query(ll,rr,lson);
if(rr>mid) ans=ans|query(ll,rr,rson);
return ans;
}
int get(int x)
{
int ans=0, y;
while(x)
{
y=x%2;
if(y)
ans++;
x/=2;
}
return ans;
}
int main()
{
int n, t, q, a, b, c, i;
char ch;
pow1[0]=1;
for(i=1; i<=30; i++)
{
pow1[i]=pow1[i-1]*2;
}
scanf("%d%d%d",&n,&t,&q);
memset(lazy,0,sizeof(lazy));
for(i=1;i<=3*n;i++)
{
sum[i]=1;
}
while(q--)
{
getchar();
scanf("%c",&ch);
if(ch=='C')
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
int tt=a;
a=b;
b=tt;
}
update(a,b,pow1[c-1],1,n,1);
}
else
{
scanf("%d%d",&a,&b);
if(a>b)
{
int tt=a;
a=b;
b=tt;
}
int ans=get(query(a,b,1,n,1));
printf("%d\n",ans);
}
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

POJ 2777 Count Color(段树)的更多相关文章

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

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

  2. poj 2777 Count Color(线段树)

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

  3. POJ 2777 Count Color(线段树之成段更新)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...

  4. poj 2777 Count Color(线段树、状态压缩、位运算)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Des ...

  5. POJ 2777.Count Color-线段树(区间染色+区间查询颜色数量二进制状态压缩)-若干年之前的一道题目。。。

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53312   Accepted: 16050 Des ...

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

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

  7. poj 2777 Count Color - 线段树 - 位运算优化

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42472   Accepted: 12850 Description Cho ...

  8. poj 2777 Count Color

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

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

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

随机推荐

  1. siwft初学(一)

    今天刚開始学习swift语言.首先须要下载xcode6 beta版本号.正式版本号然后会公布.自己学习总结一下,假设有误.请大家指出. 创建project的时候.language选择swift语言. ...

  2. Could not load file or assembly&#39;System.Data.SQLite.dll&#39; or one of its depedencies

    [问题]  在我本机的开发环境c#连接sqlite3没有问题,但是release版本号移植到其它的机器就提示Could not load file or assembly'System.Data. ...

  3. ESFramework 开发手册(07) -- 掉线与心跳机制(转)

    虽然我们前面已经介绍完了ESFramework开发所需掌握的各种基础设施,但是还不够.想要更好地利用ESFramework这一利器,有些背景知识是我们必须要理解的.就像本文介绍的心跳机制,在严峻的In ...

  4. linux 文件查看目录的数

    ls -l | grep '^-'| wc -l ls -l | grep -c '^-' ls -l 输出文件夹中的文件信息的一长串(注意,文件,不同于文件,它可能是一个文件夹.联系.设备文件) g ...

  5. sql分隔字符串数组

    declare @relation_code nvarchar(1024) set @relation_code = '#10000#10002' set @relation_code=substri ...

  6. POJ 1798 Truck History

    Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for v ...

  7. wind river hypervisor 2.0.2.1

    2692407267@qq.com,请注意很多其他内容http://user.qzone.qq.com/2692407267 wind river hypervisor 2.0.2.1 版权声明:本文 ...

  8. 同台交换机同样VLAN能够通信,不同VLAN不可通信

    一.示意图 二.IP规划 PC0:192.168.0.100  255.255.255.0        PC1:192.168.0.110  255.255.255.0        PC2:192 ...

  9. 左右db_block_size了解和实验

    关于db_block_gets了解和实验 实验 一. 自己手动创建的小表 创建一个区大小为  40k  SYS@ORCL>show parameter db_block_size NAME   ...

  10. net搭建热插拔式web框架(沙箱的构建)

    net搭建热插拔式web框架(沙箱的构建) 上周五写了一个实现原理篇,在评论中看到有朋友也遇到了我的问题,真的是有种他乡遇知己的感觉,整个系列我一定会坚持写完,并在最后把代码开源到git中.上一篇文章 ...