以下代码是错的,仅用于存储而用
#include<iostream>
#include<cstdio>
#include<cstring>
const int maxn=8000+10;
#define mid ((s+t)>>1)
#define ls h<<1,s,mid
#define rs h<<1|1,mid+1,t
using namespace std;
struct node{
int c,sc,tc;
};
node a[maxn<<2];
int sum[maxn];
void init(int h,int s,int t ){
if(s==t){
a[h].c=10000;a[h].sc=a[h].tc=10000;
}else{
init(ls);
init(rs);
a[h].c=10000;a[h].sc=a[h].tc=10000;
}
}
void ts(int h,int s,int t,int L,int R,int ys){
if(L<=s && t<=R){
a[h].c=ys;a[h].sc=a[h].tc=ys;
}else{
if(a[h].c>=0){
a[h<<1].c=a[h<<1|1].c=a[h].c;
a[h].c=-1;
}
if(L<=mid)ts(ls,L,R,ys);
if(mid<R)ts(rs,L,R,ys);
a[h].sc=a[h<<1].sc;a[h].tc=a[h<<1|1].tc;
}
}
void dfs(int h,int s,int t){
if(s<t){
if(a[h].c!=-1){
a[h<<1].c=a[h<<1|1].c=a[h].c;
}
dfs(ls);
dfs(rs);
}
}
void cal(int h,int s,int t){
printf("%d %d %d %d\n",h,a[h].c,s,t);
if((s==t)){
sum[a[h].c]++;
}
else{
cal(ls);
cal(rs);
if(a[h<<1].tc==a[h<<1|1].sc)sum[a[h<<1].tc]--;
}
}
int main(){
int i,j,k,m,n,x,y,z;
while(scanf("%d",&n)!=EOF){
memset(sum,0,sizeof(sum));
init(1,1,6);
for(i=1;i<=n;i++){
scanf("%d%d%d",&x,&y,&z);
ts(1,1,4,x+1,y,z);
}
cout<<endl;
dfs(1,1,6);
cal(1,1,6);
for(i=0;i<=8000;i++)
if(sum[i])printf("%d %d\n",i,sum[i]);
}
return 0;
}