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. 【算法与数据结构】在n个数中取第k大的数(基础篇)

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 题目介绍            在n个数中取第k大的数(基础篇),之所以叫基础篇是因为还有很多更高级的算法,这些 ...

  2. ZOJ 1301 The New Villa (BFS + 状态压缩)

    题意:黑先生新买了一栋别墅,可是里面的电灯线路的连接是很混乱的(每个房间的开关可能控制其他房间,房间数<=10),有一天晚上他回家时发现所有的灯(除了他出发的房间)都是关闭的,而他想回卧室去休息 ...

  3. <<java 并发编程>>第七章:取消和关闭

    Java没有提供任何机制来安全地终止线程,虽然Thread.stop和suspend等方法提供了这样的机制,但是存在严重的缺陷,应该避免使用这些方法.但是Java提供了中断Interruption机制 ...

  4. Linux下有线无线网络配置------命令模式

    1. 列出启用网络设备的所有信息: ifconfig 2. 将网络设备设置为启用或者不启用 不启用设备eth0 ifconfig eth0 down 启用设备eth0: Will bring eth0 ...

  5. Android上传文件到服务器(转)

    Android中实现上传文件,其实是很简单的,和在java里面是一样的,基本上都是熟悉操作输出流和输入流!还有一个特别重要的就是需要配置content-type的一些参数!如果这些都弄好了,上传就很简 ...

  6. 浪漫桃心的Android表白程序

    本文转载于  huachao1001的专栏 几年前,看到过有个牛人用HTML5绘制了浪漫的爱心表白动画.地址在这:浪漫程序员 HTML5爱心表白动画.发现原来程序员也是可以很浪……漫…..的.那么在A ...

  7. Vijos P1325桐桐的糖果计划(有向图双连通分量)

    /*重边不能删 不能删 不能删...*/ #include<iostream> #include<cstdio> #include<cstring> #define ...

  8. jQuery 图片轮播

    HTML <div class="carousel">    <ul class="car-img">        <li> ...

  9. 实用iPhone Cydia插件

      BadgeClear(角标清除):可以清除App推送所在图标右上角出现的红色角标.在桌面长按图标后,图标开始左右摇动,再双击图标即可清除点击的图标角标.   Bitesms(短信):收费插件,具有 ...

  10. Websocket 与代理服务器如何交互? How HTML5 Web Sockets Interact With Proxy Servers

    How HTML5 Web Sockets Interact With Proxy Servers Posted by Peter Lubberson Mar 16, 2010 With the re ...