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 ...
随机推荐
- iOS 开发仿网易云音乐歌词海报
使用网易云音乐也是一个巧合,我之前一直使用QQ音乐听歌,前几天下 app 手机内存告急.于是就把QQ音乐给卸载掉了,正好晚上朋友圈里有一个朋友用网易云音乐分享了一首歌曲,于是我也就尝试下载了网易云音乐 ...
- 为什么选性别会导致兴趣都选中-vue
为什么选性别会导致兴趣都选中-vue <%@ page language="java" import="java.util.*" pageEncoding ...
- Android-Universal-Image-Loader学习笔记(3)--内存缓存
前面的两篇博客写了文件缓存.如今说说Android-Universal-Image-Loader的内存缓存.该内存缓存涉及到的类如图所看到的 这些类的继承关系例如以下图所看到的: 如同文件缓存一样,内 ...
- 晋IT分享成长沙龙集锦
第一期"晋IT"分享成长沙龙于2014年7月19日圆满结束.下面是相关内容整理和第二期预告. 各位伙伴认真的介绍自己,介绍自己的业务,分析自己眼下存在的问题,大家一起探讨,真诚出谋 ...
- Android-HttpURLConnection自己主动管理cookie
Volley那么好用的框架居然没有内置对cookie的处理,自己搞一个! public class MobCookieManager {//转载请标明出处:http://blog.csdn.net/g ...
- cocos2d-x-lua基础系列教程一(hello lua)
myscene.lua function ERROR_TRACBACK(msg) print (==========) print ("lua error is "..tostri ...
- zzulioj--1790-- 弹珠游戏(数学水题!)
弹珠游戏 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 14 Solved: 10 SubmitStatusWeb Board Descriptio ...
- [codeforces 894 E] Ralph and Mushrooms 解题报告 (SCC+拓扑排序+DP)
题目链接:http://codeforces.com/problemset/problem/894/E 题目大意: $n$个点$m$条边的有向图,每条边有一个权值,可以重复走. 第$i$次走过某条边权 ...
- http扩展请求头中的x-Forwarded-For
X-Forwarded-For格式: X-Forwarded-For: client-ip, proxy1-ip, proxy2-ip 客户端请求服务器的过程中没经过一个代理层(代理中使用了xff)那 ...
- 用jQuery设置多个css样式
$("#show_one").css({"position":"fixed","top":"0px" ...