题目:http://poj.org/problem?id=2777

状压每个颜色的选择情况,取答案时 | 一番;

注意题目中的区间端点可能大小相反,在读入时换一下位置;

注意pushdown()中要lazy标签不为0才进行更新。

代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
int const N=;
int t[N],lazy[N],len,tt,o;
char dc;
void pushdown(int x)
{
if(lazy[x])//!
{
lazy[x*]=lazy[x];
lazy[x*+]=lazy[x];
t[x*]=lazy[x];
t[x*+]=lazy[x];
lazy[x]=;
}
}
void pushup(int x)
{
t[x]=(t[x*]|t[x*+]);
}
void build(int l,int r,int x)
{
t[x]=;
if(l==r)return;
int mid=(l+r)/;
build(l,mid,x*);
build(mid+,r,x*+);
}
void update(int l,int r,int ll,int rr,int s,int x)
{
if(l>=ll&&r<=rr)
{
t[x]=s;
lazy[x]=s;
return;
}
pushdown(x);
int mid=(l+r)/;
if(mid>=ll)update(l,mid,ll,rr,s,x*);
if(mid<rr)update(mid+,r,ll,rr,s,x*+);
pushup(x);
}
int query(int l,int r,int ll,int rr,int x)
{
int ans=;
if(l>=ll&&r<=rr)
return t[x];
pushdown(x);
int mid=(l+r)/;
if(mid>=ll)ans|=query(l,mid,ll,rr,x*);
if(mid<rr)ans|=query(mid+,r,ll,rr,x*+);
return ans;
}
int main()
{
while(scanf("%d%d%d",&len,&tt,&o)==)
{
build(,len,);
while(o--)
{
cin>>dc;
// printf("(%c)\n",dc);
if(dc=='C')
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(x>y)swap(x,y);
z=(<<(z-));
update(,len,x,y,z,);
}
if(dc=='P')
{
int x,y;
scanf("%d%d",&x,&y);
if(x>y)swap(x,y);
int k=query(,len,x,y,);
int ans=;
for(int i=;i<=tt;i++)
if(k&(<<(i-)))ans++;
printf("%d\n",ans);
}
}
}
return ;
}

poj2777Count Color——线段树+状压的更多相关文章

  1. POJ:2777-Count Color(线段树+状压)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Description Chosen Problem Solving and Program d ...

  2. hdu 5023 线段树+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...

  3. POJ 3468 线段树+状压

    题意:给你n个数,有对区间的加减操作,问某个区间的和是多少. 思路:状压+线段树(要用lazy标记,否则会TLE) //By SiriusRen #include <cstdio> #in ...

  4. Bzoj 3813 奇数国 题解 数论+线段树+状压

    3813: 奇数国 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 748  Solved: 425[Submit][Status][Discuss] ...

  5. POJ-2777Count Color 线段树+位移

    这道题对于我这样的初学者还是有点难度的不过2遍A了还是很开心,下面说说想法-- Count Color Time Limit: 1000MS Memory Limit: 65536K Total Su ...

  6. poj2777--Count Color(线段树,二进制转化)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34950   Accepted: 10542 Des ...

  7. HDU_3071 Gcd & Lcm game 【素数分解 + 线段树 + 状压】

    一.题目  Gcd & Lcm game 二.分析 非常好的一题. 首先考虑比较暴力的做法,肯定要按区间进行处理,对于$lcm$和$gcd$可以用标准的公式进行求,但是求$lcm$的时候是肯定 ...

  8. C++-POJ2777-Count Color[线段树][lazy标记][区间修改]

     分析:https://www.bilibili.com/read/cv4777102 #include <cstdio> #include <algorithm> using ...

  9. 【bzoj4006】[JLOI2015]管道连接 斯坦纳树+状压dp

    题目描述 给出一张 $n$ 个点 $m$ 条边的无向图和 $p$ 个特殊点,每个特殊点有一个颜色.要求选出若干条边,使得颜色相同的特殊点在同一个连通块内.输出最小边权和. 输入 第一行包含三个整数 n ...

随机推荐

  1. matlab2016b-linux版本在ubutu16.04x64上面不能打开摄像头的处理方法

    this  can  not  work.    need  find  other way.   ================================================== ...

  2. centOS中修改语言环境

    在终端中打开 键入 vim ~/.bashrc 在最后一行键入 export LANG="zh_CH.UTF-8"

  3. memcached 搭建

     linux 下memcached 的搭建 memcached 下载地址:http://www.danga.com/memcached/dist/ libevent 下载地址:http://libev ...

  4. 【转】soapUI和Jmeter的接口测试结构区别

    使用SoapUI和Jmeter都可以进行自动化接口测试,但是每个工具都有自身的特点,所以他们的结构也有一定的区别 SoapUI 项目名称 -Rest服务.Rest资源 在使用SoapUI进行接口测试时 ...

  5. 【题解】[CJOI2019]Cipher

    [题解][CJOI2019]Cipher 题目描述 给定你\(p\)进制数\(s\),\(p \le 9+26\),求对于十进制数\(k\),求\(k^s \equiv ? \mod m\) 数据范围 ...

  6. 利用socket.io实现多人聊天室(基于Nodejs)

    socket.io简单介绍 在Html5中存在着这种一个新特性.引入了websocket,关于websocket的内部实现原理能够看这篇文章.这篇文章讲述了websocket无到有,依据协议,分析数据 ...

  7. linux安装mongodb,设为全局和后台启动

    curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.5.tgz # 下载 tar -zxvf mongodb-linux ...

  8. Java中的迭代迭代器Iterator与枚举器Enumeration

    Iterator 和 Enumeration区别 Iterator 和 Eumberation都是Collection集合的遍历接口,我们先看下他们的源码接口 package java.util; p ...

  9. Java for LeetCode 085 Maximal Rectangle

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  10. LeetCode:用最少的箭引爆气球【452】

    LeetCode:用最少的箭引爆气球[452] 题目描述 在二维空间中有许多球形的气球.对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标.由于它是水平的,所以y坐标并不重要,因此只要知道 ...