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. SpringBoot 配置文件 application.properties

    转:http://www.qiyadeng.com/post/spring-boot-application-properties #########COMMON SPRING BOOT PROPER ...

  2. MongoDB 逻辑与操作

    看下面两个例子 rs1:PRIMARY> db.display.find({$and: [{$where: '(1386813645 - this.last_active_time > 3 ...

  3. Android--图片的三级缓存策略

    三级缓存缓存(内存)--->本地磁盘---->网络1.首先看一下图片存储到本地磁盘 public class FileUtils { String path;//文件存储的地方 publi ...

  4. UVA 11212 IDA*

    移动一块连续的区间使得数列递增.问最少次数. 直接IDA*暴搜,只是我没有想到A*函数,所以就随手写了个连续递增块数作为估价函数,WA了,然后除以2,还是WA,除以3,WA,除以4...过了= = # ...

  5. QML官方系列教程——QML Applications

    附网址:http://qt-project.org/doc/qt-5/qmlapplications.html 假设你对Qt的官方demo感兴趣,能够參考本博客的另一个系列Qt5官方demo解析集 每 ...

  6. ios中xib的使用介绍

    ios中Xib的使用 ios中xib的使用 Nib files are the quintessential(典型的) resource type used to create iOS and Mac ...

  7. android ToolBar与DrawerLayout笔记

    通过Android Studio 生成的Nagvition DrawerLayout Activity 自带的布局中的NagvitionView会覆盖ToolBar直接通到statusBar. 但是自 ...

  8. apk代码的破解

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

  9. 模板-->中国剩余定理[互质版本]

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 扩展欧几里得extend_gcd模板 poj_1006_Biorhythms,my_ac_code 简单的测试 None ...

  10. 使用MiniProfiler调试Asp.net Mvc性能

    使用nuget添加MiniProfiler.EF组件 在Global文件中配置MiniProfiler protected void Application_Start() { AreaRegistr ...