【题目链接】

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

【算法】

线段树

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010 int N,T,Q,l,r,x,v;
char op[]; struct SegmentTree
{
struct Node
{
int l,r,s,tag;
} Tree[MAXN<<];
inline void build(int index,int l,int r)
{
Tree[index].l = l;
Tree[index].r = r;
Tree[index].s = ;
if (l == r) return;
int mid = (l + r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
}
inline void pushdown(int index)
{
if (Tree[index].tag)
{
Tree[index<<].s = Tree[index<<|].s = << (Tree[index].tag - );
Tree[index<<].tag = Tree[index<<|].tag = Tree[index].tag;
Tree[index].tag = ;
}
}
inline void update(int index)
{
Tree[index].s = Tree[index<<].s | Tree[index<<|].s;
}
inline void modify(int index,int l,int r,int val)
{
if (Tree[index].l == l && Tree[index].r == r)
{
Tree[index].s = << (val - );
Tree[index].tag = val;
return;
}
pushdown(index);
int mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) modify(index<<,l,r,val);
else if (mid + <= l) modify(index<<|,l,r,val);
else
{
modify(index<<,l,mid,val);
modify(index<<|,mid+,r,val);
}
update(index);
}
inline int query(int index,int l,int r)
{
if (Tree[index].l == l && Tree[index].r == r) return Tree[index].s;
pushdown(index);
int mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) return query(index<<,l,r);
else if (mid + <= l) return query(index<<|,l,r);
else return query(index<<,l,mid) | query(index<<|,mid+,r);
}
} S;
inline int calc(int x)
{
int ret = ;
while (x)
{
if (x & ) ret++;
x >>= ;
}
return ret;
} int main()
{ scanf("%d%d%d",&N,&T,&Q);
S.build(,,N);
while (Q--)
{
scanf("%s",&op);
if (op[] == 'C')
{
scanf("%d%d%d",&l,&r,&x);
if (l > r) swap(l,r);
S.modify(,l,r,x);
} else
{
scanf("%d%d",&l,&r);
if (l > r) swap(l,r);
v = S.query(,l,r);
printf("%d\n",calc(v));
}
} return ; }

【POJ 2777】 Count Color的更多相关文章

  1. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  2. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  3. BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )

    虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...

  4. 【POJ 1741】Tree

    Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11570   Accepted: 3626 Description ...

  5. 【BZOJ2287】【POJ Challenge】消失之物 背包动规

    [BZOJ2287][POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了 ...

  6. 背包DP【bzoj2287】: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. &q ...

  7. bzoj2287【POJ Challenge】消失之物(退背包)

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 657  Solved: 382[Submit][S ...

  8. BZOJ 2287 【POJ Challenge】消失之物(DP+容斥)

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 986  Solved: 572[Submit][S ...

  9. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

随机推荐

  1. Unity中带有alpha通道的视频叠加播放

    问题: 如何让两个透明视频叠加播放 解决播放: 1:使用Unity自带的shader,shader代码如下所示 Shader "Unlit/MaskVideo" { Propert ...

  2. org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;

    升级springboot到2.0时,碰到了一大堆问题,上面异常原因是jar版本冲突了,有的模块忘记更新版本了,统一一下版本就可以了

  3. Group共享网元

    熟悉TWaver的用户都知道Group的概念,如果是Group,那必然会出现一个网元在多组的情况,最近有客户遇到这个问题,给写了Demo,这些也跟大家分享一下如何实现,先让我们看看共享网元的效果. 熟 ...

  4. 12Cookie、Session

    12Cookie.Session-2018/07/24 1.保存会话数据 cookie客户端技术,把每个用户的数据以cookie的形式写给用户各自的浏览器 HttpSession服务端技术,服务器运行 ...

  5. Qt 给QWidget添加工具栏

    在Qt中,给主窗口(QMainWindow类)添加工具栏非常方便,直接使用addToolBar 即可,如下所示: fileToolBar = addToolBar(tr("&File ...

  6. UVA-1572 Self-Assembly(拓扑排序判断有向环)

    题目: 给出几种正方形,每种正方形有无穷多个.在连接的时候正方形可以旋转.翻转. 正方形的每条边上都有一个大写英文字母加‘+’或‘-’.00,当字母相同符号不同时,这两条边可以相连接,00不能和任何边 ...

  7. Django中的模板变量

    示例文件: template_variable_demo.zip

  8. STM32 实现 4*4 矩阵键盘扫描(HAL库、标准库 都适用)

    本文实现的代码是基于STM32HAL库的基础上的,不过标准库也可以用,只是调用的库函数不同,逻辑跟配置是一样的,按我这里的逻辑来配置即可. 1.键盘原理图: 原理举例:先把 F0-F7 内部拉高,这样 ...

  9. 【Codeforces 1036C】Classy Numbers

    [链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...

  10. 特种部队(codevs 1427)

    题目描述 Description 某特种部队接到一个任务,需要潜入一个仓库.该部队士兵分为两路,第一路士兵已经在正面牵制住了敌人,第二路士兵正在悄悄地从后方秘密潜入敌人的仓库.当他们到达仓库时候,发现 ...