CF 377D Developing Game 【思维+线段树+扫描线】

传送门


SOL

L m a x ≤ V m i n , V m a x ≤ R m i n ; Lmax\le Vmin,Vmax\le Rmin; LmaxVmin,VmaxRmin;

e q u a l s   E x i s t   P ( x , y ) , L ≤ x P ≤ V , V ≤ y P ≤ R . equals\ Exist\ P(x,y),L\le x_P\le V,V\le y_P\le R. equals Exist P(x,y),LxPV,VyPR.


CODE

#include<bits/stdc++.h>
#define pf printf
#define sf scanf
#define cs const
#define ll long long
#define db double
#define ri register int
using namespace std;
cs int N=3e5+10;
struct node{
	int ql,qr,k,x;
	bool operator <(cs node &t)cs {
		return x==t.x? k>t.k:x<t.x;
	}
}q[N<<1];
struct people{
	int l,v,r;
}pp[N];
int n,ans=0,cnt=0,up=0,sx,sy;
struct tree{
	#define lc (p<<1)
	#define rc ((p<<1)|1)
	int mx[N<<2],tag[N<<2],y[N<<2];
	inline void pushup(int p){mx[p]=max(mx[lc],mx[rc]);y[p]=mx[p]==mx[lc]? y[lc]:y[rc];}
	inline void pushnow(int p,int k){mx[p]+=k;tag[p]+=k;}
	inline void pushdown(int p){if(tag[p])pushnow(lc,tag[p]),pushnow(rc,tag[p]);tag[p]=0;}
	inline void build(int p,int l,int r){
		y[p]=r;
		if(l^r){
			int mid=(l+r)>>1;
			build(lc,l,mid);build(rc,mid+1,r);
		}
	}
	inline void update(int p,int l,int r,int ql,int qr,int k){
		if(ql<=l&&r<=qr){
			return pushnow(p,k);
		}
		pushdown(p);
		int mid=(l+r)>>1;
		if(ql<=mid)update(lc,l,mid,ql,qr,k);
		if(qr>mid)update(rc,mid+1,r,ql,qr,k);
		pushup(p);
	}
}tre;
signed main (){
	sf("%d",&n);
	for(ri i=1;i<=n;++i){
		sf("%d%d%d",&pp[i].l,&pp[i].v,&pp[i].r);
		if(pp[i].v<pp[i].l||pp[i].v>pp[i].r)continue;
		up=max(up,pp[i].r);
		q[++cnt]=(node){pp[i].v,pp[i].r,1,pp[i].l};
		q[++cnt]=(node){pp[i].v,pp[i].r,-1,pp[i].v};
	}
	sort(q+1,q+cnt+1);
	tre.build(1,1,up);
	for(ri i=1;i<=cnt;++i){
		tre.update(1,1,up,q[i].ql,q[i].qr,q[i].k);
		if(tre.mx[1]>ans)ans=tre.mx[1],sx=q[i].x,sy=tre.y[1];
	}
	cout<<ans<<'\n';
	for(ri i=1;i<=n;++i){
		if(pp[i].l<=sx&&pp[i].v>=sx&&pp[i].v<=sy&&pp[i].r>=sy)cout<<i<<' ';
	}
	   return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值