poj 2777Count Color
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的更多相关文章
- POJ 1046 Color Me Less 最详细的解题报告
题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ M ...
- POJ:2777-Count Color(线段树+状压)
Count Color Time Limit: 1000MS Memory Limit: 65536K Description Chosen Problem Solving and Program d ...
- 组合数学 - 波利亚定理 --- poj : 2154 Color
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7873 Accepted: 2565 Description ...
- poj 1046 ——Color Me Less
提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7630 Accepted: 2507 Description ...
- POJ 2054 Color a Tree
贪心.... Color a Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: ...
- poj 1046 Color Me Less
Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33007 Accepted: 16050 D ...
- poj 2154 Color——带优化的置换
题目:http://poj.org/problem?id=2154 置换的第二道题! 需要优化!式子是ans=∑n^gcd(i,n)/n (i∈1~n),可以枚举gcd=g,则有phi( n/g )个 ...
- POJ 1046 Color Me Less(浅水)
一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The sol ...
随机推荐
- BIGINT UNSIGNED value is out of range in … 问题的解决方法
问题出现在CAST(value AS USIGNED)将字符串转换成数值的过程中,出现这个问题的原因是value对应的数值在BIGINT UNSIGNED 的范围内.可能的情况是value的值太大,超 ...
- python list排序的两种方法及实例讲解
对List进行排序,Python提供了两个方法方法1 用List的内建函数list sort进行排序list sort(func=None, key=None, reverse=False)Pytho ...
- Getting Started with the NDK
The Native Development Kit (NDK) is a set of tools that allow you to leverage C and C++ code in your ...
- 最小圆覆盖 hdu 3007
今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...
- .net之页面生面周期
# 事件或方法 功能 描述 1 Init 事件 页面初始化 页面生存周期中的第一个阶段是初始化.当 Init 事件发生时,在.aspx 源文件中静态声明的所有控件都已实例化并取其默认值.应该注意的是, ...
- HDU5348
题意:给一个无向图,让你指定边的方向,比如a→b为1,a←b为0,在给所有边指定方向后,对无向图上的每个顶点,如果满足|出度-入度|<2,那么输出一种方案. 思路:从结论入手,|出度-入度|&l ...
- NET平台下的Excel编程|C#操作Excel|Application和ApplicationClass的联系和区别
NET平台下的Excel编程|C#操作Excel|Application和ApplicationClass的联系和区别 1. Interop含义Interop是互操作的含义.Microsoft.Off ...
- eclipse打包jar时包含第三方jar包的相关问题
我用的是mars4.5版本的eclipse 需求:要把写好的工程打成jar包,并能直接运行.工程用了若干个第三方jar. 在打包的时候,eclipse提供的打包方法不能引用第三方jar包,导致了出现C ...
- scn转换为十进制
- Linux文件编程实例
//捕获fopen调用中的错误 #include <stdio.h> #include <errno.h> #include <string.h> #define ...