稍微解释一下第一组测试数据:
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
0 4 4不能理解为0~4这5个节点,而应该理解为0~1;1~2; 2~3; 3~4这4个线段颜色涂为4
这样就能解释1 1这个output了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lson l,mid,dex<<1
#define rson mid+1,r,dex<<1|1
#define havemid int mid = (l + r)>>1
using namespace std;
const int mx = 10010;
int tage[mx<<2];
int key[mx<<2];
int color[mx<<2];
void Push_down(int dex)
{
if(tage[dex] != -1)
{
tage[dex<<1] = tage[dex<<1|1] = tage[dex];
key[dex<<1] = key[dex<<1|1] = key[dex];
tage[dex] = -1;
}
}
struct po
{
int x1,x2,c;
} point[mx<<2];
void updata(int L, int R, int c, int l, int r, int dex)
{
if(L>R) return;
if(L<=l && R>=r)
{
key[dex] = c;
tage[dex] = 1;
return;
}
// if(l == r) return;
Push_down(dex);
havemid;
if(L <= mid) updata(L, R, c, lson);
if(R > mid) updata(L, R, c, rson);
}
void query(int &ans, int& last, int l, int r, int dex)
{
if(l == r)
{
if(last != key[dex] && key[dex] != -1)
{
color[key[dex]]++;
last = key[dex];
}
else if(key[dex] == -1)
last = -1;
return;
}
Push_down(dex);
havemid;
query(ans,last,lson);
query(ans,last,rson);
}
int main()
{
// freopen("1610.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
memset(key, -1, sizeof(key));
memset(tage, -1, sizeof(tage));
int edge = 1;
for(int i=1; i<=n; i++)
{
scanf("%d %d %d",&point[i].x1,&point[i].x2,&point[i].c);
point[i].x1++;
point[i].x2++;
edge = max(edge , max(point[i].x1 , point[i].x2));
}
for(int i=1; i<=n; i++)
{
updata(point[i].x1+1, point[i].x2, point[i].c, 1, edge, 1);
}
memset(color,0,sizeof(color));
int ans = 0;
int tem = -1;
query(ans,tem,1,edge,1);
for(int i=0;i<=8010;i++)
{
if(color[i])
printf("%d %d\n",i,color[i]);
}
printf("\n");
}
return 0;
}