第一次没想到用位运算,不出意料的T了,,,

PS:在床上呆了接近两个月后,我胡汉三又杀回来刷题啦~~

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxn=100004;
using namespace std;
int sum[maxn<<2];
int col[maxn<<2];
void pushDown(int rt)
{
if(sum[rt]){
col[rt<<1]=col[rt<<1|1]=1<<(sum[rt]-1);
sum[rt<<1]=sum[rt<<1|1]=sum[rt];
sum[rt]=0;
}
}
void update(int c,int L,int R,int l,int r,int rt)
{
if(l>=L&&R>=r)
{
sum[rt]=c;
col[rt]=1<<(sum[rt]-1);
// cout<<rt<<"##"<<col[rt]<<endl;
return;
}
if(L>r||R<l)
return ;
if(sum[rt])
pushDown(rt);
int m=(l+r)>>1;
if(m>=L) update(c,L,R,lson);
if(m<R) update(c,L,R,rson);
col[rt]=col[rt<<1]|col[rt<<1|1];
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
return col[rt];
}
if(L>r||R<l)
return 0;
pushDown(rt);
int m=(l+r)>>1;
return query(L,R,lson)|query(L,R,rson);
/*if(m>=L) query(L,R,lson);
if(m<R) query(L,R,rson);
return col[rt<<1]|col[rt<<1|1];*/
}
int main()
{
int l,t,o;
while(scanf("%d%d%d",&l,&t,&o)!=EOF)
{
getchar();
char p;
int a,b,c;
sum[1]=1;col[1]=1;
for(int i=0; i<o; i++)
{
scanf("%c",&p);
getchar();
if(p=='P')
{
scanf("%d%d",&a,&b);
if(a>b)
{
int x=a;a=b;b=x;
}
getchar();
int tem=query(a,b,1,l,1);
int ans=0;
//cout<<tem<<"tem"<<endl;
while(tem)
{
ans+=tem&1;
tem>>=1;
}
printf("%d\n",ans);
}
else
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
int x=a;a=b;b=x;
}
getchar();
update(c,a,b,1,l,1);
//cout<<col[2]<<"update"<<endl;
}
}
}
return 0;
}

poj_2777线段树+位运算的更多相关文章

  1. poj 3225 线段树+位运算

    略复杂的一道题,首先要处理开闭区间问题,扩大两倍即可,注意输入最后要\n,初始化不能随便memset 采用线段树,对线段区间进行0,1标记表示该区间是否包含在s内U T S ← S ∪ T 即将[l, ...

  2. hdu 5023 线段树+位运算

    主要考线段树的区间修改和区间查询,这里有一个问题就是这么把一个区间的多种颜色上传给父亲甚至祖先节点,在这里题目告诉我们最多30颜色,那么我们可以把这30中颜色用二进制储存和传给祖先节点,二进制的每一位 ...

  3. poj 2777 Count Color - 线段树 - 位运算优化

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42472   Accepted: 12850 Description Cho ...

  4. Codeforces 620E New Year Tree(线段树+位运算)

    题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...

  5. Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

    链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...

  6. Count Color(线段树+位运算 POJ2777)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...

  7. POJ 2777 Count Color(线段树+位运算)

    题目链接:http://poj.org/problem?id=2777 Description Chosen Problem Solving and Program design as an opti ...

  8. 【洛谷】【线段树+位运算】P2574 XOR的艺术

    [题目描述:] AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为n的01串. 2. 给定一个范围[ ...

  9. [poj2777] Count Color (线段树 + 位运算) (水题)

    发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...

随机推荐

  1. http响应的封装

    响应的封装: 资源的初始化 分析请求响应信息,根据状态响应码,发送不同的状态码 浏览器根据状态信息,做出不同的执行 构建正文,也就是根据浏览器客服端的请求发送响应信息: 发送响应:code 是状态码, ...

  2. 简单谈谈MySQL优化利器-慢查询

    慢查询 首先,无论进行何种优化,开启慢查询都算是前置条件.慢查询机制,将记录过慢的查询语句(事件),从而为DB维护人员提供优化目标. 检查慢查询是否开启 通过show variables like ' ...

  3. POJ3684 Physics Experiment 【物理】

    Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1031   Accepted: 365 ...

  4. Pointcut is not well-formed: expecting 'name pattern' at character position 36

    Pointcut is not well-formed: expecting 'name pattern' at character position 36 学习了:http://blog.csdn. ...

  5. JavaFX学习之道:JavaFX之TableView

    TableView表     TableColumn列  构建一个表主要有TableView,TableColumn,ObservableList,Bean.  加入列table.getColumns ...

  6. sqlite学习笔记9:C语言中使用sqlite之插入数据

    前面创建了一张表,如今给他插入一些数据.插入数据跟创建表差点儿相同,不过SQL语言不一样而已,完整代码例如以下: #include <stdio.h> #include <stdli ...

  7. Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可运行文件

    学了一阵子Python,拿来做个什么有意思的东西呢?爬糗百好了.爬到的内容,邮件分发出去. 然后又啃了两天的wxpython,做了个简易的邮件管理界面,能够在这里添加或者删除邮件,而且一键爬虫发送. ...

  8. xBIM 基础10 WeXplorer 浏览器检查

    系列目录    [已更新最新开发文章,点击查看详细]  在上一篇 <xBIM基础 09 WeXplorer 基本应用> 已经提到,查看器不会在所有浏览器的所有设备上运行.为了操作效率和简单 ...

  9. Elasticsearch之四种查询类型和搜索原理(博主推荐)

    Elasticsearch Client发送搜索请求,某个索引库,一般默认是5个分片(shard). 它返回的时候,由各个分片汇总结果回来. 官网API https://www.elastic.co/ ...

  10. 004.ES2015和ES2016新特性--块级作用域变量

    其基本原理就是JavaScript的作用域链,下面以对比的方式来展示一下函数级作用域和块级作用域. 函数级作用域 var fns = []; for (var i = 0; i < 5 ; i+ ...