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 ...
随机推荐
- 监控myserver计数器
- maven这些工具负责创建项目,然后maven负责打包好war包扔进tomcat容器,tomcat容器接受的只是jar包
maven这些工具负责创建项目,然后maven负责打包好war包扔进tomcat容器,tomcat容器接受的只是jar包 2.tomcat不管你什么编译的,也不管你开发工具是什么.Tomcat只接受w ...
- Qt之命令行参数
简述 在Qt之进程间通信(QProcess)一节,我们讲解了如何通过QProcess来进行进程间的通信.主要通过启动外部程序,然后通过命令行的方式传递参数. 这里,我们可以通过Qt Creator来设 ...
- python多线程编程代码
参考了这篇文章,写的挺好的. http://blog.csdn.net/abcjennifer/article/details/49474897 import time import threadin ...
- MySQL优化之——集群搭建步骤具体解释
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46833179 1 概述 MySQL Cluster 是MySQL 适合于分布式计算 ...
- jdbc14 及 jdbc16 共存所带来的问题【未完待续】
在JAVA中JDK版本号与JDBC版本号的一致性十分重要,开发都们经常会忽略了这一点导致非常多不必要的错误. 昨天给客户排查了一个关于EDB在JBoss中使用时关于这方面的问题,希望给大家一点启示. ...
- MyBatis数据持久化(九)动态sql
本文摘自:mybatis参考文档中文版 MyBatis的一个强大的特性之一通常是它的动态SQL能力.如果你有使用JDBC或其他相似框架的经验,你就明白条件地串联SQL字符串在一起是多么的痛苦,确保不能 ...
- (转载)RecyclerView之ItemDecoration由浅入深
RecyclerView之ItemDecoration由浅入深 作者 小武站台 关注 2016.09.19 18:20 字数 1155 阅读 10480评论 15喜欢 91赞赏 3 译文的GitHub ...
- Thread-local storage
Thread-local storage (TLS) is a computer programming method that uses static or global memory local ...
- 大数相乘(牛客网ac通过)
2019-05-172019-05-17 大数相乘基本思想: 相乘相加,只不过大于10先不进位到计算完后统一进位 #include <iostream> #include <stri ...