职务地址:

id=2777">POJ 2777

我去。。

延迟标记写错了。标记到了叶子节点上。。

这根本就没延迟嘛。。

。怪不得一直TLE。。。

这题就是利用二进制来标记颜色的种类。然后利用或|这个符号来统计每一个区间不同颜色种数。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
int sum[410000];
int lazy[410000];
int pow1[40];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]|sum[rt<<1|1];
}
void PushDown(int rt)
{
if(lazy[rt])
{
lazy[rt<<1]=lazy[rt];
lazy[rt<<1|1]=lazy[rt];
sum[rt<<1]=lazy[rt];
sum[rt<<1|1]=lazy[rt];
lazy[rt]=0;
}
}
void update(int ll, int rr, int c, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
sum[rt]=c;
lazy[rt]=c;
return ;
}
PushDown(rt);
int mid=l+r>>1;
if(ll<=mid) update(ll,rr,c,lson);
if(rr>mid) update(ll,rr,c,rson);
PushUp(rt);
}
int query(int ll, int rr, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
return sum[rt];
}
PushDown(rt);
int ans=0;
int mid=l+r>>1;
if(ll<=mid) ans=ans|query(ll,rr,lson);
if(rr>mid) ans=ans|query(ll,rr,rson);
return ans;
}
int get(int x)
{
int ans=0, y;
while(x)
{
y=x%2;
if(y)
ans++;
x/=2;
}
return ans;
}
int main()
{
int n, t, q, a, b, c, i;
char ch;
pow1[0]=1;
for(i=1; i<=30; i++)
{
pow1[i]=pow1[i-1]*2;
}
scanf("%d%d%d",&n,&t,&q);
memset(lazy,0,sizeof(lazy));
for(i=1;i<=3*n;i++)
{
sum[i]=1;
}
while(q--)
{
getchar();
scanf("%c",&ch);
if(ch=='C')
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
int tt=a;
a=b;
b=tt;
}
update(a,b,pow1[c-1],1,n,1);
}
else
{
scanf("%d%d",&a,&b);
if(a>b)
{
int tt=a;
a=b;
b=tt;
}
int ans=get(query(a,b,1,n,1));
printf("%d\n",ans);
}
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

POJ 2777 Count Color(段树)的更多相关文章

  1. poj 2777 Count Color(线段树区区+染色问题)

    题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查 ...

  2. poj 2777 Count Color(线段树)

    题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ 2777 Count Color(线段树之成段更新)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Descrip ...

  4. poj 2777 Count Color(线段树、状态压缩、位运算)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Des ...

  5. POJ 2777.Count Color-线段树(区间染色+区间查询颜色数量二进制状态压缩)-若干年之前的一道题目。。。

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53312   Accepted: 16050 Des ...

  6. POJ 2777 Count Color (线段树成段更新+二进制思维)

    题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的 ...

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

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

  8. poj 2777 Count Color

    题目连接 http://poj.org/problem?id=2777 Count Color Description Chosen Problem Solving and Program desig ...

  9. POJ 2777 Count Color(线段树染色,二进制优化)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 Des ...

随机推荐

  1. windows任务设置定时

    windows 的Schedule Task .创建一个配置 1.点击"开始" 2.点击"控制面板" 3.双击"任务计划程序" 4.双击&q ...

  2. CSS预处理器——Sass、LESS和Stylus实践

    CSS(Cascading Style Sheet)被译为级联样式表,做为一名前端从业人员来说,这个专业名词并不陌生,在行业中通常称之为“风格样式表(Style Sheet)”,它主要是用来进行网页风 ...

  3. PocketSphinx语音识别系统语言模型的训练和声学模型的改进

    PocketSphinx语音识别系统语言模型的训练和声学模型的改进 zouxy09@qq.com http://blog.csdn.net/zouxy09 关于语音识别的基础知识和sphinx的知识, ...

  4. 【原创】leetCodeOj --- Copy List with Random Pointer 解题报告

    题目地址: https://oj.leetcode.com/problems/copy-list-with-random-pointer/ 题目内容: A linked list is given s ...

  5. 联想A798T刷机包 基于百度云V6 集成RE3.1.7美化版 精简冗余文件

    ROM介绍 1.apk进行odex合并及zipaliang优化-省电及降低内存暂用. 2.測试相机.通话.数据.wifi.蓝牙.等传感器均正常,. 3.提供时间居中防iphone状态栏补丁 4.增加I ...

  6. 【Unity技能】做一个简单的NPC

    1. 写在前面 前几天我看到cgcookie一个教程.学习了下怎么依据已有人物模型制作一个仿版的NPC人物.感觉挺好玩的,整理一下放到博客里! 先看一下教程里面的终于效果. 是不是非常像个幽灵~ 以下 ...

  7. RH133读书笔记(1)-Lab 1 Managing Startup

    Lab 1 Managing Startup Goal: To familiarize yourself with the startup process System Setup: A system ...

  8. hdu 4661 Message Passing(木DP&amp;组合数学)

    Message Passing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  9. UI标签库的话题:JEECG智能开发平台 BaseTag(样式表和JS标签的引入)

    UI标签库专题一:JEECG智能开发平台 BaseTag(样式表和JS引入标签) 1.BaseTag(样式表和JS引入标签) 1.1. 演示样例 <t:base type="jquer ...

  10. 开源 自由 java CMS - FreeCMS1.9 评论管理

    项目地址:http://code.google.com/p/freecms/ 评论管理 1. 评论管理 从左側管理菜单点击评论管理进入. 2. 评论审核 选择须要审核的评论,然后点击"审核& ...