__Chtholly @ 2023-07-16 16:51:25
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const ll N=3005;
ll n,m;
ll a1[N],b1[N];
ll val[N];
ll a[N],b[N];
ll ans;
struct node{
ll l,r,tag,num;
}Tree[N<<2];
void build(ll l,ll r,ll rt){
Tree[rt].l=l,Tree[rt].r=r;
if(l==r)return ;
ll m=(l+r)/2;
build(l,m,rt<<1),build(m+1,r,rt<<1|1);
}
void pushdown(ll rt){
if(Tree[rt].num){
Tree[rt<<1].num=Tree[rt].num;
Tree[rt<<1|1].num=Tree[rt].num;
Tree[rt].num=0;
}
return ;
}
void update(ll rt,ll L,ll R,ll val){
ll l=Tree[rt].l,r=Tree[rt].r;
if(r<L||l>R)return ;
if(L<=l&&r<=R){
Tree[rt].num=val;
return ;
}
pushdown(rt);
update(rt<<1,L,R,val);
update(rt<<1|1,L,R,val);
return ;
}
ll cnt[N<<1];
void pushit(ll rt){
if(Tree[rt].l==Tree[rt].r)return ;
pushdown(rt);
pushit(rt<<1),pushit(rt<<1|1);
}
void findit(ll rt){
if(Tree[rt].l==Tree[rt].r){
cnt[Tree[rt].l]=Tree[rt].num;
return ;
}
pushdown(rt);
findit(rt<<1),findit(rt<<1|1);
}
bool tmp[N<<2];
signed main(){
scanf("%lld%lld",&n,&m);
for(register ll i=1;i<=m;++i){
scanf("%lld%lld",&a1[i],&b1[i]);
val[i*2-1]=a1[i];
val[i*2]=b1[i];
}
val[2*m+1]=n;
sort(val+1,val+1+m*2+1);
ll tot=unique(val+1,val+1+2*m+1)-val-1;
for(register ll i=1;i<=m;++i){
ll pos1,pos2;
pos1=lower_bound(val+1,val+1+tot,a1[i])-val;
pos2=lower_bound(val+1,val+1+tot,b1[i])-val;
a[i]=pos1;
b[i]=pos2;
}
n=lower_bound(val+1,val+1+tot,n)-val;
build(1,n,1);
for(register ll i=1;i<=m;++i)
update(1,a[i],b[i],i);
for(register ll i=1;i<=m;++i)pushit(1);
findit(1);
for(register ll i=1;i<=n;++i)
if(!tmp[cnt[i]] && cnt[i])
ans++,tmp[cnt[i]]=1;
printf("%lld\n",ans);
return 0;
}
by __Chtholly @ 2023-07-19 18:28:34
所以有人吗/kk
by zimmy @ 2023-11-09 19:17:51
离散化的时候把a1[i]+1和b1[i]+1也放进val数组里应该就行了(我也是这个地方错了!!)
比如说有三个区间是[1,2][4,5][1,5],原本应该三个区间都能被看到,但你这样离散化后中间的间隔没了会变成[1,2][3,4][1,4],[1,4]被覆盖只剩两个区间了