蒟蒻stl像个憨憨,编译都不过
  • 板块学术版
  • 楼主Episode9
  • 当前回复14
  • 已保存回复14
  • 发布时间2020/6/8 16:26
  • 上次更新2023/11/7 00:59:27
查看原帖
蒟蒻stl像个憨憨,编译都不过
37409
Episode9楼主2020/6/8 16:26
#include<bits/stdc++.h>
#define Maxn 250005
using namespace std;
struct node{int x,y,l;}T[Maxn];
int N,L,lsh[Maxn<<1],top=0,cnt,f[Maxn];
deque <int> Q;
inline void read(int &x)
{
	int f=1;x=0;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
int id=0;
struct tree{int ls,rs,Min;deque <int> q;}Tree[40000005];
struct segy
{
	inline void update(int &root,int l,int r,int wzy,int x)
	{
		if (!root) root=++id;
		if (l==r) {if (x==99999999)Tree[root].q.pop_front();else Tree[root].q.push_back(x);if (!Tree[root].q.size()) Tree[root].Min=99999999;else Tree[root].Min=Tree[root].q.front();return;}
		int mid=l+r>>1;
		if (wzy<=mid) update(Tree[root].ls,l,mid,wzy,x);
		else update(Tree[root].rs,mid+1,r,wzy,x);
		Tree[root].Min=min(Tree[Tree[root].ls].Min,Tree[Tree[root].rs].Min);
	}
	inline int ask(int root,int l,int r,int ly,int ry)
	{
		if (!root) return 99999999;
		if (l==ly&&r==ry) return Tree[root].Min;
		int mid=l+r>>1;
		if (ry<=mid) return ask(Tree[root].ls,l,mid,ly,ry);
		if (ly>mid) return ask(Tree[root].rs,mid+1,r,ly,ry);
		if (ly<=mid&&ry>mid) return min(ask(Tree[root].ls,l,mid,ly,mid),ask(Tree[root].rs,mid+1,r,mid+1,ry));
	}
}; 
struct segx
{
	int rt[Maxn<<2];
	segy TTT[Maxn<<2];
	inline void update(int root,int l,int r,int wzx,int wzy,int x)
	{
		TTT[root].update(rt[root],1,cnt,wzy,x);
		if (l==r) return;
		int mid=l+r>>1;
		if (wzx<=mid) update(root<<1,l,mid,wzx,wzy,x);
		else update(root<<1|1,mid+1,r,wzx,wzy,x);
	}
	inline int ask(int root,int l,int r,int lx,int rx,int ly,int ry)
	{
		if (l==lx&&r==rx) return TTT[root].ask(rt[root],1,cnt,ly,ry);
		int mid=l+r>>1;
		if (rx<=mid) return ask(root<<1,l,mid,lx,rx,ly,ry);
		if (lx>mid) return ask(root<<1|1,mid+1,r,lx,rx,ly,ry);
		if (lx<=mid&&rx>mid) return min(ask(root<<1,l,mid,lx,mid,ly,ry),ask(root<<1|1,mid+1,r,mid+1,rx,ly,ry));
	}
}TT;
int main()
{
	Tree[0].Min=99999999;
	read(N),read(L);T[1].x=0,T[1].y=2e9,T[1].l=0;lsh[++top]=0,lsh[++top]=2e9;
	for (int i=2;i<=N;i++) read(T[i].x),read(T[i].y),read(T[i].l),lsh[++top]=T[i].x,lsh[++top]=T[i].y;
	sort(lsh+1,lsh+top+1);
	cnt=unique(lsh+1,lsh+top+1)-lsh-1;
	for (int i=1;i<=N;i++) T[i].x=lower_bound(lsh+1,lsh+cnt+1,T[i].x)-lsh,T[i].y=lower_bound(lsh+1,lsh+cnt+1,T[i].y)-lsh;
	Q.push_back(1);f[1]=0;TT.update(1,1,cnt,T[1].y,T[1].x,f[1]);
	for (int i=2;i<=N;i++)
	{
		while (!Q.empty()&&T[i].l-T[Q.front()].l>L) TT.update(1,1,cnt,T[Q.front()].y,T[Q.front()].x,99999999),Q.pop_front();
		int tmp=TT.ask(1,1,cnt,T[i].x,cnt,1,T[i].y);
		if (tmp!=99999999) f[i]=tmp+1,TT.update(1,1,cnt,T[i].y,T[i].x,f[i]);
		else f[i]=-1;
//		f[i]=999999999;
//		for (int j=Q.front();j<i;j++) if (T[i].x<=T[j].y&&T[i].y>=T[j].x) f[i]=min(f[i],f[j]+1);
		Q.push_back(i);
		cout<<f[i]<<'\n';
	} 	
	return 0;	
} 

RT,我树套树套了个deque然后编译都过不了力,像个**,求救

2020/6/8 16:26
加载中...