
题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出。
思路 :线段树区间更新一下,然后标记一下,最后从头输出。
//ZOJ 1610
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std ; int p[*],lz[*] ,hashh[*],hash1[*]; //void pushup(int rt)
//{
// if(p[rt << 1] == p[rt << 1 | 1])
// p[rt] = p[rt << 1] ;
// else p[rt] = -1 ;
//}
void pushdown(int rt)
{
if(lz[rt] != -)
{
lz[rt << ] = lz[rt << | ] = lz[rt] ;
p[rt << ] = p[rt << | ] = lz[rt] ;
lz[rt] = - ;
}
}
//void build(int l,int r,int rt)
//{
// lz[rt] = -1 ;
// if(l == r)
// {
// p[rt] = -1 ;
// return ;
// }
// int mid = (l + r) >> 1 ;
// build(l,mid,rt << 1) ;
// build(mid+1,r,rt << 1 | 1) ;
// pushup(rt) ;
//}
void update(int L,int R,int l,int r,int rt,int sc)
{
if(l >= L && r <= R)
{
lz[rt] = sc ;
p[rt] = sc ;
return ;
}
pushdown(rt) ;
int mid = (l+r) >> ;
if(mid >= L)
update(L,R,l,mid,rt << ,sc) ;
if(mid < R)
update(L,R,mid+,r,rt << | ,sc) ;
// pushup(rt) ;
}
void query(int l,int r,int rt)
{
if(l == r)
{
hashh[l] = p[rt] ;
return ;
}
pushdown(rt) ;
int mid = (l+r) >> ;
query(l,mid,rt << ) ;
query(mid+,r,rt << | ) ;
}
void Init()
{
memset(lz,-,sizeof(lz)) ;
memset(hashh,,sizeof(hashh)) ;
memset(hash1,,sizeof(hash1)) ;
memset(p,-,sizeof(p)) ;
}
int main()
{
int n ,x1,x2,c;
while(cin >> n )
{
Init() ;
for(int i = ; i < n ; i++)
{
cin >> x1 >> x2 >> c ;
update(x1,x2-,,,,c) ;
}
query(,,) ;
for(int i = ; i <= ; i++)
{
if(hashh[i] != hashh[i-])
{
if(hashh[i-] != -)
hash1[hashh[i-]] ++ ;
}
}
if(hashh[] != -)
hash1[hashh[]]++ ;
for(int i = ; i <= ;i++)
{
if(hash1[i])
{
printf("%d %d\n",i,hash1[i]) ;
}
}
puts("") ;
}
return ;
}