题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6301
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MA=100000+5;
struct nod
{
int x;
int y;
bool operator < (const nod&ax)const
{
if(x==ax.x)
return y>ax.y;
return x<ax.x;
}
} s[MA];
int ar[MA];
int pre[MA];
int main()
{
int t,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
memset(ar,0,sizeof ar);
memset(pre,-1,sizeof pre);
for(int i=0; i<b; i++)
scanf("%d%d",&s[i].x,&s[i].y);
sort(s,s+b);
int ma=s[0].x;
for(int i=0; i<b; i++)
if(i==0||s[i].y>ma)
{
int li=ma+1,ri=s[i].y;
if(i==0||s[i].x>ma)
li=s[i].x;
int de=1;
for(int j=li; j<=ri; j++)
{
while(pre[de]>=s[i].x)
de++;
ar[j]=de;
pre[de]=j;
}
ma=max(ma,s[i].y);
}
for(int i=1; i<=a; i++)
printf("%d%c",ar[i]==0?1:ar[i],i==a?'\n':' ');
}
}