题目: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. linux下网卡绑定

    网卡绑定的作用:1.冗余,防止单点故障 2.防止传输瓶颈 1.交换机端口绑定: system-view link-aggregation group 1 mode manual 比如把端口1和2进行绑 ...

  2. 【转】cmd chcp命令切换字符格式

    cmd chcp命令切换字符格式   命令介绍:   chcp 65001   #换成utf-8代码页   chcp 936       #换成默认的gbk   chcp 437       #美国英 ...

  3. Android 超高仿微信图片选择器 图片该这么载入

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/39943731,本文出自:[张鸿洋的博客] 1.概述 关于手机图片载入器,在当今像 ...

  4. 多线程快速解压FastZipArchive介绍

    本文转载至  http://blog.csdn.net/xunyn/article/details/12975937   多线程解压iosfast 在iOS项目中用到解压缩,用的是ZipArchive ...

  5. EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.

    EasyPusher作为一款RTSP推送利器, 配合EasyDarwin开源流媒体服务器,在发布伊始,很快获得了广大人民群众的一致好评. 但是也有一些用户反映: EasyPusher在我的华为手机上会 ...

  6. 使用@Scheduled注解编写spring定时任务

    import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframewor ...

  7. 九度OJ 1074:对称平方数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4804 解决:2173 题目描述: 打印所有不超过n(n<256)的,其平方具有对称性质的数. 如11*11=121 输入: 无任何输 ...

  8. bmdiff snappy lzw gzip

    https://github.com/google/snappy Introduction [速度第一,压缩比适宜] [favors speed over compression ratio] Sna ...

  9. Java语言基础(回头复习)

    /* 使用变量的时候要注意的问题: A:作用域 变量定义在哪个大括号内,它就在这个大括号内有效. 并且,在同一个大括号内不能同时定义同名的变量. B:初始化值 没有初始化值的变量不能直接使用. 你只要 ...

  10. [egret+pomelo]实时游戏杂记(3)

    [egret+pomelo]学习笔记(1) [egret+pomelo]学习笔记(2) [egret+pomelo]学习笔记(3) 服务端的请求流程走完了一遍,下面就该看一下,在目前的服务端中,各服务 ...