第一次没想到用位运算,不出意料的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. WCF与WEB API区别

  2. angular-API

    AngularJS 全局 API 用于执行常见任务的 JavaScript 函数集合,如: 比较对象 迭代对象 转换对象 API 描述 angular.lowercase() 转换字符串为小写 ang ...

  3. Spring中基于Java的配置@Configuration和@Bean用法 (转)

    spring中为了减少xml中配置,可以生命一个配置类(例如SpringConfig)来对bean进行配置. 一.首先,需要xml中进行少量的配置来启动Java配置: <?xml version ...

  4. Android之——自己定义TextView

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47082241 在这一篇博文中,将向大家介绍怎样以最简单的方式,来自己定义Andro ...

  5. Git-删除本地文件夹的repository(本地仓库)

    安装git软件后.有些文件夹里会出现带有?的图标,右键菜单上会有"Git-Sync"或者"Git-Commit"等命令:正常的应该是"Git-Clon ...

  6. bzoj4590: [Shoi2015]自动刷题机(二分答案)

    4590: [Shoi2015]自动刷题机 题目:传送门 题解: 很明显的一道二分题. 对于二分性的判断:如果n越大,那么AC的题就越少,n越小,AC的题就越多,那么最大最小值都满足单调性,直接瞎搞. ...

  7. MYSQL INT(N)以及zerofill的使用区别

    MYSQL中,int(n)括号里面的数据n无论写成多少,都是占4个字节的空间,最多能够存10位数.N不代表能够存多少位数,显示宽度M与数据所占用空间,数值的范围无关. 如果在定义字段的时候指定zero ...

  8. 洛谷P1339 [USACO09OCT]热浪Heat Wave(最短路)

    题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...

  9. 问题集锦 ~ jQuery

    #addClass失败 $target.addClass('show'); show 这个单词可能和内部某处起冲突了吧,有时成功有时失败,只能换个class名了,难受……

  10. dev c++与VC assist的杂记

    最近要处理一些数据,于是把旧本拿出来用用.但是发现旧本运行速度很慢. 分析之后发现是瑞星的老版本程序里面加了游戏的云存储节点的注册表键.果断把该键删了之后,CPU使用率从66%以上降到24%左右. 然 ...