题目: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. asp.net core 系列之Reponse caching之cache in-memory (2)

    这篇文章(主要翻译于官网,水平有限,见谅)讲解asp.net core 中的 Cache in-memory (内存缓存). Cache in-memory in ASP.NET Core Cachi ...

  2. (4.5.4)Android測试TestCase单元(Unit test)測试和instrumentationCase单元測试

    Android单元和instrumentation单元測试 Developing Android unit and instrumentation tests Android的单元測试是基于JUnit ...

  3. php 字符串内容是数组格式 转换成数组

    一个简单的应用.. 例, $str    =    "array( 'USD'=>'1', 'GBP'=>'0.6494', 'EUR'=>'0.7668' ,'JPY'= ...

  4. 相机标准之onvif---开放型网络视频接口论坛onvif 简介

    什么是ONVIF ? ONVIF:原意为 开放型网络视频接口论坛,即 Open Network Video Interface Forum ,是安讯士.博世.索尼等三家公司在2008年共同成立的一个国 ...

  5. PHP、AJAX综合练习(增、删、改、查、分页、模糊查询)

    先来几张效果图 主页面分页显示: 关键字查询,关键字描红 添加数组,弹出窗口,点击保存,再不刷新页面的同时添加到网页数据 修改界面:弹出窗口,文本框中保留点击的车辆的原始信息 主页面代码 <me ...

  6. 九度OJ 1058:反序输出 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8454 解决:3042 题目描述: 输入任意4个字符(如:abcd), 并按反序输出(如:dcba) 输入: 题目可能包含多组用例,每组用例 ...

  7. kafka source type

    https://flume.apache.org/FlumeUserGuide.html # example.conf: A single-node Flume configuration # Nam ...

  8. MySQL基于二进制日志的主从复制

    一.什么是MySQL的主从复制? MySQL可以将一个数据库设置为主库,另一个数据库设置为该主库的从库,当主库发生了变更,会同步到从库中.MySQL的主从架构,可以是星型的,也可以是线型的. 星型架构 ...

  9. Qt & MySQL

    Qt中如何进行MySQL连接与操作步骤: 1.向工程中的.pro文件增加QT += sql; 2.写一个通用的数据库连接类(Connect),一个static方法(CreateConnection), ...

  10. plsql连接oracle 64位数据库ORA-12514错误

    今天帮小师妹还原数据库,删除表空间的时候把数据库搞坏了,plsql连接时报了 ORA-12514: TNS:listener does not currently know of service re ...