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. STUCTS LABLE ‘S BENEFIT

    {LJ?Dragon}[注]Struts标签的三个好处 RELATED LINKS 0.UTF-8 有无BOM的区别 UTF-8 BOM 06. 几款网页数据抓取软件 SOFTWARE_INTRODU ...

  2. 安装 Panda3D 并使用原有的Python

    Part 1:什么是Panda3D [原始网站] [中文版本] Part 2:注意事项 Panda3D的版本必须与Python相匹配 Part 3:使用已安装的Python 将‘C:\Panda3D- ...

  3. OpenCV LDA(Linnear Discriminant analysis)类的使用---OpenCV LDA演示样例

    1.OpenCV中LDA类的声明 //contrib.hpp class CV_EXPORTS LDA { public: // Initializes a LDA with num_componen ...

  4. [PWA] 17. Cache the photo

    To cache photo, You need to spreate cache db to save the photo. So in wittr example, we cache the te ...

  5. IOS UIButton使用详解

    第一.UIButton的定义 UIButton *button=[[UIButton buttonWithType:(UIButtonType); 能够定义的button类型有以下6种, typede ...

  6. 论C++与三国

    Scott Meyers曾说过,C++语言是一个语言联邦.C++包含面向过程,面向对象,泛型编程编程思想.现在C++11有加了一堆新特性,语言联邦更为庞大. 程序员们.常常挑起语言之争,甚至连大师级人 ...

  7. [转] add-apt-repository

    PS: 有些项目提供的是deb 地址,那么把deb地址加到repository里,下面是一个例子: sudo apt-get update sudo add-apt-repository 'deb h ...

  8. 模板-->单变元模线性方程

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 extend_gcd模板 poj_2115_C Looooops,my_ac_code 简单的测试 None 代码模板 / ...

  9. MyBatis 学习总结(二)

    1.MyBatis基础环境的搭建 1.1 核心配置文件mybatis-config.xml <?xml version="1.0" encoding="UTF-8& ...

  10. (转帖) 有限狀態機FSM coding style整理 (SOC) (Verilog)

    来源:http://www.codesoso.net/Record/101092_95120_21.html 来源:http://www.cnblogs.com/oomusou/archive/201 ...