本地跑不起来交上去能过..
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 10000;
struct node{
int l, r;
int x;
}tr[N];
int col[N], ans[N];
void build( int l, int r, int rt )
{
tr[rt].l = l;
tr[rt].r = r;
tr[rt].x = -1;
if( l == r )
return;
int mid = ( l + r ) >> 1;
build( lson );
build( rson );
}
void update( int l, int r, int rt, int x )
{
if( l <= tr[rt].l && tr[rt].r <= r )
{
tr[rt].x = x;
return;
}
if( tr[rt].x != -1 )
{
tr[rt<<1].x = tr[rt<<1|1].x = tr[rt].x;
tr[rt].x = -1;
}
int mid = ( tr[rt].l + tr[rt].r ) >> 1;
if( r <= mid )
update( l, r, rt << 1, x );
else if( l > mid )
update( l, r, rt << 1 | 1, x );
else
{
update( lson, x );
update( rson, x );
}
}
void query( int l, int r, int rt )
{
if( tr[rt].l == tr[rt].r )
{
col[l] = tr[rt].x;
return;
}
int mid = ( l + r ) >> 1;
if( tr[rt].x != -1 )
{
tr[rt<<1].x = tr[rt<<1|1].x = tr[rt].x;
tr[rt].x = -1;
}
query( lson );
query( rson );
}
int main()
{
int l, r, c;
int n;
while(~scanf("%d", &n))
{
build( 1, 8001, 1 );
for( int i = 1; i <= n; i++ )
{
scanf("%d%d%d", &l, &r, &c);
if( l > r )
swap( l, r );
l++;
update( l, r, 1, c );
}
memset( ans, 0, sizeof( ans ) );
memset( col, 0, sizeof( col ) );
query( 1, 8001, 1 );
col[0] = -1;
for( int i = 1; i <= 8001; i++ )
{
if( col[i] != -1 && col[i] != col[i-1] )
ans[ col[i] ]++;
}
for( int i = 0; i <= 8001; i++ )
{
if( ans[i] > 0 )
printf("%d %d\n", i, ans[i]);
}
puts("");
}
return 0;
}