why RE
  • 板块学术版
  • 楼主Luka__Modric
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/3/10 17:55
  • 上次更新2024/3/10 19:52:02
查看原帖
why RE
839893
Luka__Modric楼主2024/3/10 17:55
#include <bits/stdc++.h>
using namespace std;
struct node{
	int l,r,tag;
};
struct segment{
	int l,r;
}a[200010];
node tree[200010];
int n;
bool cmp(segment x,segment y){
	if(x.l==y.l){
		return x.r<y.r;
	}
	return x.l<y.l;
}
void buildtree(int p,int l,int r){
	if(l>r)
		return ;
	tree[p].l=l,tree[p].r=r;
	if(l==r){
		if(l==1)
			tree[p].tag=0;
		return ;
	}
	buildtree(p*2,l,(l+r)/2),buildtree(p*2+1,(l+r)/2+1,r);
}
void modify(int p,int l,int r,int k){
	if(tree[p].l>r||tree[p].r<l)
		return ;
	if(tree[p].l>=l&&tree[p].r<=r){
		tree[p].tag=min(tree[p].tag,k);
		return;
	}
	modify(p*2,l,(l+r)/2,k),modify(p*2+1,(l+r)/2+1,r,k);
}
int query(int p,int q){
	return min(tree[p].l==tree[p].r?1000000000:(q<=tree[p*2].r?query(p*2,q):query(p*2+1,q)),tree[p].tag);
}
int main(){
	cin>>n;
	for(int i=1;i<=4*n;i++)
		tree[i].tag=1e9+10;
	buildtree(1,1,n);
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		modify(1,a[i].l,a[i].r,query(1,a[i].l)+1);
	cout<<query(1,n);
    return 0;
}


/*
       ┏┓   ┏┓
     ┏┛┻━━━┛┻┓
     ┃       ┃
     ┃   ━   ┃
     ┃ ┳┛ ┗┳ ┃
     ┃       ┃
     ┃   ┻   ┃
     ┃       ┃
     ┗━┓   ┏━┛Codes are far away from bugs with the animal protecting
         ┃   ┃    神兽保佑,代码无bug
         ┃   ┃
         ┃   ┗━━━┓
         ┃      ┣┓
         ┃     ┏┛w
         ┗┓┓┏━┳┓┏┛
           ┃┫┫ ┃┫┫
           ┗┻┛ ┗┻┛     ○| ̄|_

*/

2024/3/10 17:55
加载中...