1 #include<cstdio>
 2 #include<cstring>
 3 #define MAXN 8010
 4 int tree[MAXN<<2],color[MAXN],ans[MAXN];
 5 inline void PushDown(int rt)
 6 {
 7     if(tree[rt]!=-1)
 8     {
 9         tree[rt<<1]=tree[rt<<1|1]=tree[rt];
10         tree[rt]=-1;
11     }
12 }
13 void Update(int x,int y,int val,int L,int R,int rt)
14 {
15     if(x<=L&&R<=y)
16         tree[rt]=val;
17     else
18     {
19         int mid=(L+R)>>1;
20         PushDown(rt);
21         if(mid>=x)
22             Update(x,y,val,L,mid,rt<<1);
23         if(y>mid)
24             Update(x,y,val,mid+1,R,rt<<1|1);
25     }
26 }
27 void Query(int L,int R,int rt)
28 {
29     if(tree[rt]!=-1)
30     {
31         for(int i=L;i<=R;i++)
32             color[i]=tree[rt];
33     }
34     else if(L!=R)
35     {
36         int mid=(L+R)>>1;
37         Query(L,mid,rt<<1);
38         Query(mid+1,R,rt<<1|1);
39     }
40 }
41 int main()
42 {
43     int n,x,y,val,i,j;
44     while(~scanf("%d",&n))
45     {
46         memset(tree,-1,sizeof(tree));
47         memset(color,-1,sizeof(color));
48         memset(ans,0,sizeof(ans));
49         while(n--)
50         {
51             scanf("%d%d%d",&x,&y,&val);
52             if(x<y)
53                 Update(x+1,y,val,1,MAXN,1);
54         }
55         Query(1,MAXN,1);
56         for(i=0;i<MAXN;i++)
57         {
58             if(color[i]!=-1)
59             {
60                 for(j=i;j<MAXN&&color[i]==color[j];j++);
61                 ans[color[i]]++;
62                 i=j-1;
63             }
64         }
65         for(i=0;i<MAXN;i++)
66         {
67             if(ans[i])
68                 printf("%d %d\n",i,ans[i]);
69         }
70         putchar('\n');
71     }
72     return 0;
73 }
posted on 2012-05-22 16:22  DrunBee  阅读(305)  评论(0编辑  收藏  举报