poj_2777线段树+位运算
第一次没想到用位运算,不出意料的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线段树+位运算的更多相关文章
- poj 3225 线段树+位运算
略复杂的一道题,首先要处理开闭区间问题,扩大两倍即可,注意输入最后要\n,初始化不能随便memset 采用线段树,对线段区间进行0,1标记表示该区间是否包含在s内U T S ← S ∪ T 即将[l, ...
- hdu 5023 线段树+位运算
主要考线段树的区间修改和区间查询,这里有一个问题就是这么把一个区间的多种颜色上传给父亲甚至祖先节点,在这里题目告诉我们最多30颜色,那么我们可以把这30中颜色用二进制储存和传给祖先节点,二进制的每一位 ...
- poj 2777 Count Color - 线段树 - 位运算优化
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42472 Accepted: 12850 Description Cho ...
- Codeforces 620E New Year Tree(线段树+位运算)
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...
- 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 ...
- Count Color(线段树+位运算 POJ2777)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Descrip ...
- POJ 2777 Count Color(线段树+位运算)
题目链接:http://poj.org/problem?id=2777 Description Chosen Problem Solving and Program design as an opti ...
- 【洛谷】【线段树+位运算】P2574 XOR的艺术
[题目描述:] AKN觉得第一题太水了,不屑于写第一题,所以他又玩起了新的游戏.在游戏中,他发现,这个游戏的伤害计算有一个规律,规律如下 1. 拥有一个伤害串为长度为n的01串. 2. 给定一个范围[ ...
- [poj2777] Count Color (线段树 + 位运算) (水题)
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Pro ...
随机推荐
- Docker 管理工具的选择:Kubernetes 还是 Swarm?
[编者的话]选择Kubernetes 或者 Swarm 就像在将 Linux 桌面发行版的范围缩小到两个后选出一个最喜欢的.哪个更满足你的需要如何才是决定因素. [3 天烧脑式基于Docker的CI/ ...
- ASP.NET-js和C#混合编程的例子
使用<text>这个伪元素来强制Razor从编译模式返回到内容模式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
- 【原创】Zend Framework 2框架之MVC
ZendFramework 2框架之MVC 作者:sys(360电商技术组) 1.前言 Zend Framework 2是zend官方推出的php开源框架,基于php5.3.他全然採用面向对象的代码实 ...
- MongoDB之Java測试代码(DAO层)
MongoInit.java是数据库初始化及连接类 MongoUtils.java是对mongodb的各种操作方法 MongoInit.java package com.wlwcloud.datate ...
- Android中文API-ViewStub
ViewStub控件是一个不可见,0尺寸得惰性控件.当ViewStub控件设置可见,或者调用inflate(),并运行完毕之后,ViewStub所指定的layout资源就会被载入.这个ViewStub ...
- node17
一.复习 cookie是在res中设置,req中读取的.第一次的访问没有cookie. cookie的存储大小有限,kv对.对用户可见,用户可以禁用.清除Cookie.可以被篡改. cookie用来制 ...
- oracle 11g sql优化之行迁移处理(加大BLOCK块)
行链接 产生原因:当一行数据大于一个数据块,ORACLE会同时分配两个数据块,并在第一个块上登记第二个块的地址,从而形成行链接. 预防方法:针对表空间扩大数据块大小.检查:analyze table ...
- pthread 的 api 分类
pthreads defines a set of C programming language types, functions and constants. It is implemented w ...
- Docker学习笔记(1)----认识Docker
1. 什么Docker? Docker是一个能把开发的应用程序自动部署到容器的引擎,它使用go语言编写的开源引擎,它在github上面个的地址为:https://github.com/docker/d ...
- [agc016d]xor replace
题意: 题解: 棒棒的神仙题...这题只是D题???(myh:看题五分钟,讨论两小时) 首先这个异或和是假的,比如我现在有$a=(a_1,a_2,a_3,a_4)$,操作一下$a_2$,就变成了$a= ...