【POJ 2777】 Count Color
【题目链接】
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的更多相关文章
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )
虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...
- 【POJ 1741】Tree
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11570 Accepted: 3626 Description ...
- 【BZOJ2287】【POJ Challenge】消失之物 背包动规
[BZOJ2287][POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了 ...
- 背包DP【bzoj2287】: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. &q ...
- bzoj2287【POJ Challenge】消失之物(退背包)
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 657 Solved: 382[Submit][S ...
- BZOJ 2287 【POJ Challenge】消失之物(DP+容斥)
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 986 Solved: 572[Submit][S ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- 导出功能在数据库内容为数字,excel表格中是汉字的时候
代码如下: @ExcelField(title = "饮水器评价",dictType = "waterer_rate" ,align = 2, sort = 2 ...
- xilinx vivado 百度云分享 vivado2019.1 2018.3 2017.4
vivado2019.1 sdx套件 链接:https://pan.baidu.com/s/1ymRpUa2UYTFuafEChA0-ZQ 提取码:cd4p 复制这段内容后打开百度网盘手机App,操作 ...
- Windows下运行jekyll,编码已不再是问题
很久没更新jekyll了,所以好奇着去官网看了下更新记录,发现如下更新条目(版本1.3.0/2013-11-04发布): Add encoding configuration option (#144 ...
- Colletions工具类常用方法
Collections 工具类常用方法: 排序 查找,替换操作 同步控制(不推荐,需要线程安全的集合类型时请考虑使用 JUC 包下的并发集合 排序操作 void reverse(List list)/ ...
- ajax aspx调用webservice,返回json
1,创建一个asp.net网站 2.创建一个student类 using System; using System.Collections.Generic; using System.Linq; us ...
- Crackme3 破解教程
Crackme3 破解教程 1.先用PEiD对 Crackme3进行 壳测试 点击File右边的按钮,选中Crackme3 结果如下图所示: 即 无壳. 试运行软件 点击 Register now! ...
- Codeforces Round #244 (Div. 2)
今天是水题集啊.... A. Police Recruits time limit per test 1 second memory limit per test 256 megabytes inpu ...
- reids桌面管理工具:RedisDesktopManager下载、使用
概要:一款好用的Redis桌面管理工具,支持命令控制台操作,以及常用,查询key,rename,delete等操作. 下载软件,请点击下面链接,进入下载页,选择对应版本: https://redisd ...
- Oracle删除约束和主键的语句
https://blog.csdn.net/xue_yanan/article/details/78210654?locationNum=8&fps=1
- Ubuntu下非常规方法安装绿色软件(压缩包)
继上一篇http://www.cnblogs.com/EasonJim/p/7117567.html文章中说的常规方式安装的软件,都会自动在命令行及Dash Home中体现. 但是如果是使用压缩包进行 ...