hdu6301[多校第一场D]

链接:hdu6301[多校第一场D]

题解

  • 当时忘了set自带排序功能2333,TLE无数发
  • 思路很简单,断开的区间很好处理,无脑填就好,又重复区间的时候,a[lst].l~a[i].l-1这一段是可以重复使用的,把它放到set,然后依次填就好。具体看代码吧0.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<set>
#include<algorithm>
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define repd(i,x,y) for(register int i=x;i>=y;--i)
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=1e5+7;
const int M=1e5+7;
struct node{
int l,r;
}a[N],tp[N];
int T,n,m,ans[N];
set<int>st;
inline int cmp(node x,node y){return x.l!=y.l?x.l<y.l:x.r<y.r;}
int main(){
scanf("%d",&T);
while(T--){
st.clear();
scanf("%d%d",&n,&m);
rep(i,1,n)st.insert(i);
memset(ans,0,sizeof(ans));
rep(i,1,m){
scanf("%d%d",&a[i].l,&a[i].r);
}
sort(a+1,a+m+1,cmp);
int lst=0;
rep(i,1,m){
if(a[i].l<=a[lst].r&&a[i].r<=a[lst].r)continue;
if(a[i].l<=a[lst].r){
rep(j,a[lst].l,a[i].l-1)st.insert(ans[j]);
rep(j,a[lst].r+1,a[i].r){
ans[j]=*st.begin();
st.erase(ans[j]);
}
}
else {
if(i!=1)rep(j,a[lst].l,a[lst].r)if(!st.count(ans[j]))st.insert(ans[j]);
rep(j,a[i].l,a[i].r){
ans[j]=*st.begin();
st.erase(ans[j]);
}
}
lst=i;
}
rep(i,1,n)printf("%d%c",ans[i]?ans[i]:1,i!=n?' ':'\n');
}
return 0;
}