mxqz 全RE
查看原帖
mxqz 全RE
709013
__Inception__楼主2022/7/7 21:02

rt

线段树不太会写,大佬们轻喷qwq

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m;
int tag[N],ans[N];

inline int lc(int x){
	return x<<1;
} 
inline int rc(int x){
	return x<<1|1;
}

inline void pushup(int x){
	ans[x]=ans[lc(x)]+ans[rc(x)];
}
inline void pushdown(int x){
	if(tag[x]){
		tag[x]=0,tag[lc(x)]=1,tag[rc(x)]=1;
		ans[lc(x)]=0,ans[rc(x)]=0;
	}
}

void build(int x,int l,int r){
	if(l==r){
		ans[x]=1;
		return ;
	}
	int mid=(l+r)/2;
	build(lc(x),l,mid);
	build(rc(x),mid+1,r);
	pushup(x);
}

void upd(int x,int l,int r,int L,int R){
	if(L<=l&&r<=L){
		tag[x]=1,ans[x]=0;
		return ;
	}
	pushdown(x);
	int mid=(l+r)/2;
	if(L<=mid)upd(lc(x),l,mid,L,R);
	if(mid<R)upd(rc(x),mid+1,r,L,R);
	pushup(x);
}

int main(){
	scanf("%d%d",&n,&m);
	build(1,1,n+1);
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		upd(1,1,n+1,x+1,y+1);	
	}
	printf("%d",ans[1]);
	return 0;
}

2022/7/7 21:02
加载中...