BZOJ1568:[JSOI2008]Blue Mary开公司——题解

https://www.lydsy.com/JudgeOnline/problem.php?id=1568

李超线段树(不会的话去网上搜吧……)。

完。

#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long double dl;
const int N=50010;
inline dl read(){
    dl X=0,Y=1.0;int w=0;char ch=0;
    while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
    while(isdigit(ch))X=X*10+(ch^48),ch=getchar();
    if(ch=='.'){
        ch=getchar();
        while(isdigit(ch))X+=(Y/=10)*(ch^48),ch=getchar();
    }
    return w?-X:X;
}
struct node{
    int l,r;
    dl yl,yr;
    node(int x1=0,dl y1=0,int x2=0,dl y2=0){
        l=x1,r=x2;yl=y1,yr=y2;
    }
    dl k(){return (yr-yl)/(r-l);}
    dl point(int x){return l==r?yl:yl+k()*(x-l);}
    void lm(int x){yl=point(x),l=x;}
    void rm(int x){yr=point(x),r=x;}
}tr[N*4];
dl query(int a,int l,int r,int k){
    if(l==r)return tr[a].point(k); 
    int mid=(l+r)>>1;dl ans;
    if(k<=mid)ans=query(a<<1,l,mid,k);
    else ans=query(a<<1|1,mid+1,r,k);
    return max(ans,tr[a].point(k));
}
void insert(int a,int l,int r,node k){
    if(k.l<l)k.lm(l);
    if(r<k.r)k.rm(r);
    int mid=(l+r)>>1;
    if(k.point(mid)>tr[a].point(mid))swap(k,tr[a]);
    if(min(tr[a].yl,tr[a].yr)>=max(k.yl,k.yr))return;
    if(l==r)return;
    if(tr[a].k()>k.k())insert(a<<1,l,mid,k);
    else insert(a<<1|1,mid+1,r,k);
}
char s[20];
int main(){
    int n=read();
    while(n--){
        scanf("%s",s);
        if(s[0]=='Q')printf("%d\n",(int)(query(1,1,50000,read())/100));
        else{
            int x0=1,x1=50000;
            dl y0=read(),k=read(),y1=k*(x1-x0)+y0;
            node p=node(x0,y0,x1,y1);
            insert(1,1,50000,p);
        }
    }
    return 0;
}

+++++++++++++++++++++++++++++++++++++++++++

+本文作者:luyouqi233。               +

+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/+

+++++++++++++++++++++++++++++++++++++++++++

posted @ 2018-06-12 15:58  luyouqi233  阅读(145)  评论(0编辑  收藏  举报