ABC 158 F-Removing Robots dp monotonic stack

LINK:Removing Robots

I did not expect autism.

Considering a tolerable finding that the illegal scheme is difficult to calculate.

Even if it can be calculated, it is almost n ^ 2.

Considering that the left side of dp will affect the right side, so consider the right side of dp first and then the left side.

As for dp, it is natural that f [i] represents the number of solutions with so many points i ~ n.

Suppose that the first point to the right that cannot be affected is w. Then there is a transition f [i] + = f [i + 1] + f [w].

So from left to right dp can calculate all plans.

const ll MAXN=200010;
ll n,ans,top;
ll f[MAXN],g[MAXN],s[MAXN];
struct wy
{
	ll x,y;
	inline ll friend operator <(wy a,wy b){return a.x<b.x;}
}t[MAXN];
int main()
{
	freopen("1.in","r",stdin);
	get(n);
	rep(1,n,i)
	{
		ll get(x);ll get(y);
		t[i]=(wy){x,x+y-1};
	}
	sort(t+1,t+1+n);
	g[n+1]=1;
	fep(n,1,i)
	{
		f[i]=i;
		while(top&&t[i].y>=t[s[top]].x)
		{
			f[i]=max(f[i],f[s[top]]);
			--top;
		}
		s[++top]=i;
		g[i]=(g[i+1]+g[f[i]+1])%mod;
	}
	putl(g[1]);
	return 0;
}

Guess you like

Origin www.cnblogs.com/chdy/p/12687218.html