bzoj1568 [JSOI2008] Blue Mary opens a company to mark a permanent line segment tree

Maintain n straight lines, save slope and intercept.

Pay attention to the classification discussion when maintaining:

1. Both ends are greater than

2. Both ends are less than

3. The intersection is on the left of the midpoint

4. The point of intersection is to the right of the midpoint

Note:

Points are not inquiries

Initial value


code:

#include<iostream>
#include<cstdio>
using namespace std;
#define N 100005
double k[N<<2],ans,b[N<<2],K,B;
long long t;
int n,m,i,j;
char ch[55];
void gai(int o,double l,double r)
{
	if((k[o]==0&&b[o]==0)||(k[o]*l+b[o]<=K*l+B&&k[o]*r+b[o]<=K*r+B))
	{
		k[o]=K;
		b[o]=B;		
		return ;
	}
		if(k[o]*l+b[o]>=K*l+B&&k[o]*r+b[o]>=K*r+B)
	{	
		return ;
	}
	int mid=(l+r)/2;
double jd=(B-b[o])/(k[o]-K);
if(jd<=mid)
{gai(o<<1,l,mid);
if(k[o]*r+b[o]<=K*r+B)gai(o<<1|1,mid+1,r);
}
if(jd>mid)
{gai(o<<1|1,mid+1,r);
if(k[o]*l+b[o]<=K*l+B)gai(o<<1,l,mid);
}
}
void cha(int o,double l,double r)
{		ans=max(k[o]*t+b[o],ans);
	if(l==r)
	{
		return ;
	}
	int mid=(l+r)/2;
	if(t<=mid)cha(o<<1,l,mid);
	    else cha(o<<1|1,mid+1,r);	
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",ch);
		if(ch[0]=='P')
		{
			scanf("%lf%lf",&B,&K);
			B-=K;
			gai(1,1,100000);
		}else
		{
			ans=-9999999999;
			scanf("%lld",&t);
			cha(1,1,100000);			
			long long daan=ans/100;
			printf("%lld\n",daan);
		}	
	}
}


Guess you like

Origin blog.csdn.net/haobang866/article/details/79429981