zoj 1610
来源:互联网 发布:大航海时代4 mac版 编辑:程序博客网 时间:2024/05/16 12:19
View Code
#include<stdio.h>
#include<string.h>
const int MAX=8010;
#define L(x) x<<1
#define R(x) x<<1|1
#define MID(x,y) (x+y)>>1
struct {
int l,r,col;
}node[MAX*4];
int seg[MAX],col[MAX];
void init()
{
memset(node,0,sizeof(node));
memset(col,-1,sizeof(col));
}
void build(int t,int l,int r)
{
node[t].col=-1;
node[t].l=l;node[t].r=r;
if(l==r-1) return ;
int mid=MID(l,r);
build(L(t),l,mid);
build(R(t),mid,r);
}
void update(int t,int l,int r,int col)
{
if(node[t].l>=l&&node[t].r<=r)
{
node[t].col=col;
return ;
}
if(node[t].col==col) return ;
if(node[t].col>=0)//indicates that this segment is totally covered
{
node[R(t)].col=node[t].col;
node[L(t)].col=node[t].col;
node[t].col=-1;//to mark that this segment is not total covered
}
int mid=MID(node[t].l,node[t].r);
if(l>=mid)
update(R(t),l,r,col);
else
if(r<=mid)
update(L(t),l,r,col);
else
{
update(L(t),l,mid,col);
update(R(t),mid,r,col);
}
}
void query(int t,int l,int r)
{
if(node[t].col>=0)
{
for(int i=l;i<r;i++)
col[i]=node[t].col;
return ;
}
if(node[t].l==node[t].r-1) return ;
int mid=MID(node[t].l,node[t].r);
if(l>=mid)
query(R(t),l,r);
else
if(r<=mid)
query(L(t),l,r);
else
{
query(L(t),l,mid);
query(R(t),mid,r);
}
}
int main()
{
int i,n,x1,x2,color;
while(scanf("%d",&n)==1)
{
init();
build(1,0,8000);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&x1,&x2,&color);
update(1,x1,x2,color);
}
query(1,0,8000);
memset(seg,0,sizeof(seg));
for(i=0;i<MAX;i++)
if(col[i+1]!=col[i]&&col[i]!=-1)
seg[col[i]]++;
for(i=0;i<MAX;i++)
if(seg[i])
printf("%d %d\n",i,seg[i]);
printf("\n");
}
return 0;
}
- ZOJ 1610
- zoj 1610
- ZOJ 1610
- ZOJ 1610
- zoj--1610
- zoj 1610
- [ZOJ] 1610
- zoj 1610 线段树
- zoj 1610 线段树
- ZOJ 1610 解题报告
- ZOJ ACM 1610(JAVA)
- ZOJ 1610 线段树
- ZOJ-1610(区间染色)
- zoj 1610 线段树
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- hdu 4004
- pku 3164最小树形图
- hdu 4009最小树形图邻接表版
- hdu 2121
- Kinect for windows 开发入门 八:景深数据获取和使用 下
- zoj 1610
- hdu 4036
- hdu 4034 graph
- hdu 4033
- pku 1061
- poj pku2263floyd
- 约束的个数
- 用来练习邻接表结构 poj3268 pku spfa
- pku 3660