【题目链接】

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. php redis使用 常用方法

    基本 $redis = new Redis();//创建对象 $redis->connect('127.0.0.1',6379);//建立连接 $redis->delete('test') ...

  2. Oracle中的COALESCE,NVL,NVL2,NULLIF函数

    http://jingyan.baidu.com/article/fa4125acaf898e28ac7092b9.html

  3. Ubuntu下安装oh-my-zsh

    本文参考 https://www.jianshu.com/p/9a5c4cb0452d 此文已在ubuntu下确实安装成功,只不过懒得截图了,可以参照上述地址,我在他原基础上进行了一些更改. 安装Oh ...

  4. Java 十二周总结

  5. LINUX-挂载一个文件系统

    mount /dev/hda2 /mnt/hda2 挂载一个叫做hda2的盘 - 确定目录 '/ mnt/hda2' 已经存在 umount /dev/hda2 卸载一个叫做hda2的盘 - 先从挂载 ...

  6. Python-组合数据类型

    集合类型及操作 >集合类型定义 集合是多个元素的无序组合 -集合类型与数学中的集合概念一致 -集合元素之间无序,每个元素唯一,不存在相同元素 -集合元素不可更改,不能是可变数据类型 -集合用大括 ...

  7. display math in cnblog

    $a=b+c$ this is a example \(a=\frac{b}{c}\)

  8. java 数组排序并去重

    https://www.cnblogs.com/daleyzou/p/9522533.htmlimport java.lang.reflect.Array;import java.util.Array ...

  9. 如何绘制caffe网络训练曲线

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51774966 当我们设计好网络结构后, ...

  10. uestc 1904

    #include<stdio.h> #define N  1010 int min[N]; int main() { int t,n,p,ti,first,end,num,i,j,max, ...