【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 ...
随机推荐
- CAD控件:QT开发使用控件入门
1. 环境搭建: 3 1.1. 安装Qt 3 1.2. 安装Microsoft Windows SDK的调试包 6 2. QT中使用MxDraw控件 7 1.3. 引入控件 7 3. 打开DWG文件 ...
- CAD动态绘制样条线(网页版)
在CAD设计时,需要绘制样条线,用户可以设置样条线线重及颜色等属性. 主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数.详细说明如 ...
- Mybatis逆向工程使用方法
使用官方网站的mapper自动生成工具mybatis-generator-core-1.3.2来生成po类和mapper映射文件. 一.mapper生成配置文件 在generatorConfig.xm ...
- Java编辑编译及运行环境
Java编辑编译及运行环境 Microsoft Windows 编辑工具 EditPlus JDK JDK(Java Development Kit,Java开发工具包)安装JDK之后,其中bin文件 ...
- oracle数据库子查询的结果需要使用多次解决办法
with c as (select a.trandt,sum(a.tranam) tranam from tran a group by a.trandt )--将子查询抽取出来,以后可以直接用.该方 ...
- nginx+tomcat+memcache
tomcat1和tomcat2都需要安装以下配置[root@tomcat-1 ~]# yum -y install gcc openssl-devel pcre-devel zlib-devel[ro ...
- js 动态加载select触发事件
动态加载select后,手动调用一下 subjectChange函数,模拟触发change事件 function hallidChange(value) { $.ajax({ type: " ...
- UVA-1589 象棋(模拟)
题目:(传送门) 给出一个象棋的残局,下一步是黑棋走,判断黑棋是不是被将死. 思路: 读完这个题,知道是一个模拟题,然后想到用两个二维数组来模拟棋盘,一个(mp数组)用来存残局,一个(res数组)用来 ...
- DTD 文件的引入
MyBatis 有两种配置文件:核心配置文件(mybatis- config.xml)和 SQL 映射文件(mapper.xml).这两种配置文件都需要手动引入各自的 DTD 文件(mybatis-3 ...
- 全面了解cookie和session
http协议: http即超文本传输协议(万维网定义的),一种基于浏览器请求与服务器响应的链接,它是一个很纯粹的传输协议.http协议主要的特征就是它是一种无状态的协议(只针对cookie与sessi ...