http://poj.org/problem?id=2777

注意:a可能比b大

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1000010
using namespace std; int T,L,O,a,b,c;
char ch;
struct node
{
int l,r,co;
}tree[*maxn];
bool tab[]; void build(int l,int r,int i)
{
tree[i].co=;
tree[i].l=l;tree[i].r=r;
if(l<r)
{
int mid=(l+r)/;
build(l,mid,i+i);
build(mid+,r,i+i+);
}
} void update(int i)
{
if(tree[i].co>)
{
tree[i+i].co=tree[i+i+].co=tree[i].co;
}
tree[i].co=-;
} void insert1(int i,int l,int r,int co)
{
if(tree[i].l>=l&&tree[i].r<=r)
{
tree[i].co=co;
return ;
}
if(tree[i].l>r||tree[i].r<l) return ;
if(tree[i].l<tree[i].r)
{
int mid=(tree[i].l+tree[i].r)/;
update(i);
if(r<=mid) insert1(i+i,l,r,co);
else if(l>mid) insert1(i+i+,l,r,co);
else
{
insert1(i+i,l,mid,co);
insert1(i+i+,mid+,r,co);
}
}
} void serch(int l,int r,int i)
{
if(tree[i].co>)
{
tab[tree[i].co]=true;
return ;
}
if(tree[i].l<tree[i].r)
{
int mid=(tree[i].l+tree[i].r)/;
if(r<=mid) serch(l,r,i+i);
else if(l>mid) serch(l,r,i+i+);
else
{
serch(l,mid,i+i);
serch(mid+,r,i+i+);
}
}
}
int main()
{
scanf("%d%d%d",&L,&T,&O);
getchar();
build(,L,);
while(O--)
{
scanf("%c",&ch);
if(ch=='C')
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
swap(a,b);
insert1(,a,b,c);
}
else if(ch=='P')
{
scanf("%d%d",&a,&b);
memset(tab,false,sizeof(tab));
if(a>b) swap(a,b);
serch(a,b,);
int num=;
for(int i=; i<=T; i++)
{
if(tab[i]) num++;
}
printf("%d\n",num);
}
getchar();
}
return ;
}

poj 2777Count Color的更多相关文章

  1. POJ 1046 Color Me Less 最详细的解题报告

    题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ M ...

  2. POJ:2777-Count Color(线段树+状压)

    Count Color Time Limit: 1000MS Memory Limit: 65536K Description Chosen Problem Solving and Program d ...

  3. 组合数学 - 波利亚定理 --- poj : 2154 Color

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7873   Accepted: 2565 Description ...

  4. poj 1046 ——Color Me Less

    提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  5. [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7630   Accepted: 2507 Description ...

  6. POJ 2054 Color a Tree

    贪心....                    Color a Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:  ...

  7. poj 1046 Color Me Less

    Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33007   Accepted: 16050 D ...

  8. poj 2154 Color——带优化的置换

    题目:http://poj.org/problem?id=2154 置换的第二道题! 需要优化!式子是ans=∑n^gcd(i,n)/n (i∈1~n),可以枚举gcd=g,则有phi( n/g )个 ...

  9. POJ 1046 Color Me Less(浅水)

    一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The sol ...

随机推荐

  1. Django admin进阶

    1. ModelAdmin.inlines 将有外键的子类包含进视图 ,实例: class Author(models.Model): name = models.CharField(max_leng ...

  2. Android URI简单介绍

    就Android平台而言,URI主要分三个部分:scheme, authority and path.当中authority又分为host和port.格式例如以下: scheme://host:por ...

  3. 分布式系统状态下redis存储asp.net session使用第三方Providers驱动

    https://github.com/ServiceStack/ServiceStack.Redis (redis客户端组件) 注:redis服务端在windows不太稳定,一般部署在Linux下. ...

  4. Java对存储过程的调用方法 --转载

    一.Java如何实现对存储过程的调用: A:不带输出参数的 create procedure getsum <--此处为参数--> as declare @sum int<--定义变 ...

  5. RJ45口线序的理解

    RJ45线序就是TX_P / TX_N / RX_P / RX_N 四根线,分别用到的是1,2,3,6 因为TX要匹配RX,所以 线1 变成 另一端的 线3, 线2 变成 另一端的 线6 反过来也一样

  6. java的通信机制

    通信机制无非就那几种:http访问.socket访问: http又分为:jsp.servlet.html,用的就是get和post方法 socket则可分为:tcp或者udp方式 从以上内容又衍生出其 ...

  7. apk代码的破解

    方法一:dexdump方法(效果很不好,推荐指数*) 1.搜索到dexdump.exe所在目录: 2.将apk包中的**.dex文件存放到上面目录: 3.命令行中进入上面目录,执行:dexdump   ...

  8. Jquery小东西收集

    1. $(document).ready(),$(function(){}),$(window).load(),window.onload的关系与区别 $(document).ready(functi ...

  9. [转载]使用兼容ie6 ie7 ie8 FF的text-overflow:ellips

    使用兼容ie6 ie7 ie8 FF的text-overflow:ellipsis超出文本显示省略号来代替截取函数更有利于seo,如果使用截取函数,源代码中的标题是显示不完整的,即便是在title属性 ...

  10. Wpf Binding.Path设置

    Binding.Path 获取或设置绑定源属性的路径. 每个绑定通常都具有四个组件:绑定目标对象.目标属性.绑定源,以及要使用的绑定源值的路径.有关这些数据绑定概念的更多信息,请参见数据绑定概述. 使 ...