题面

传送门

题解

李超线段树板子

具体可以看这里

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
double readdb()
{
R double x=0,y=0.1,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
return x*f;
}
inline char getop(){R char ch;while((ch=getc())!='Q'&&ch!='P');return ch;}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+5;
struct node{
node *lc,*rc;double b,k,lv,rv;bool flag;
inline void ins(R double bb,R double kk,R int l,R int r){b=bb,k=kk,lv=k*l+b,rv=k*r+b,flag=1;}
inline double val(const R int &x){return k*x+b;}
}pool[N<<2],*rt;int tot;
inline node *newnode(){return &pool[tot++];}
int n,x,q;double b,k,bb,kk,res;char op;
void build(node* &p,int l,int r){
p=newnode();if(l==r)return;
int mid=(l+r)>>1;
build(p->lc,l,mid),build(p->rc,mid+1,r);
}
void query(node *p,int l,int r){
cmax(res,p->val(x));if(l==r)return;
int mid=(l+r)>>1;
if(x<=mid)query(p->lc,l,mid);
else query(p->rc,mid+1,r);
}
void update(node *p,int l,int r){
if(!p->flag)return p->ins(b,k,l,r),void();
double lv=l*k+b,rv=r*k+b;
if(lv<=p->lv&&rv<=p->rv)return;
if(lv>p->lv&&rv>p->rv)return p->ins(b,k,l,r),void();
int mid=(l+r)>>1;
double x=(b-p->b)/(p->k-k);
if(lv<=p->lv){
if(x<=mid)bb=p->b,kk=p->k,p->ins(b,k,l,r),b=bb,k=kk,update(p->lc,l,mid);
else update(p->rc,mid+1,r);
}else{
if(x<=mid)update(p->lc,l,mid);
else bb=p->b,kk=p->k,p->ins(b,k,l,r),b=bb,k=kk,update(p->rc,mid+1,r);
}
}
int main(){
// freopen("testdata.in","r",stdin);
n=50000,q=read();
build(rt,1,n);
while(q--){
op=getop();
if(op=='Q')x=read(),res=0,query(rt,1,n),print(res/100);
else b=readdb(),k=readdb(),b-=k,update(rt,1,n);
}
return Ot(),0;
}

洛谷P4254 [JSOI2008]Blue Mary开公司(李超线段树)的更多相关文章

  1. JSOI2008 Blue Mary开公司 | 李超线段树学习笔记

    题目链接:戳我 这相当于是一个李超线段树的模板qwqwq,题解就不多说了. 代码如下: #include<iostream> #include<cstdio> #include ...

  2. [JSOI2008]Blue Mary开公司[李超线段树]

    题面 bzoj luogu 好久以前听lxl讲过 咕掉了.. 竟然又遇到了 安利blog #include <cmath> #include <cstring> #includ ...

  3. BZOJ.1568.[JSOI2008]Blue Mary开公司(李超线段树)

    题目链接 线段树每个节点记录\(f(mid)\)最大的直线(在\(mid\)处函数值最大的直线),称作优势线段(还是直线啊...无所谓了). 如果是在区间插入线段会影响\(O(\log n)\)个区间 ...

  4. [bzoj1568][JSOI2008]Blue Mary开公司——李超线段树

    题目大意 题解 这道题需要用到一种叫做李超线段树的东西.我对于李超线段树,是这样理解的: 给节点打下的标记不进行下传,而是仅仅在需要的时候进行下传,这就是所谓永久化标记. 对于这道题,借用一张图, 这 ...

  5. 【BZOJ-1568】Blue Mary开公司 李超线段树 (标记永久化)

    1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 557  Solved: 192[Submit ...

  6. BZOJ-1568: Blue Mary开公司 (李超线段树)

    Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词“Query”或“Project”. 若单词为Query,则后接一个整数T,表示Blue ...

  7. P4254 [JSOI2008]Blue Mary开公司 (李超树)

    题意:插入一些一次函数线段 每次询问在x = x0处这些线段的最大值 题解:李超树模版题 维护优势线段 注意这题的输入是x=1时的b #include <iostream> #includ ...

  8. 2019.02.11 bzoj1568: [JSOI2008]Blue Mary开公司(线段树)

    传送门 题意简述:维护整体加一条线段,求单点极值. 思路: 直接上李超线段树维护即可. 代码: #include<bits/stdc++.h> #define ri register in ...

  9. [Luogu] P4254 [JSOI2008]Blue Mary开公司

    题目背景 Blue Mary 最近在筹备开一家自己的网络公司.由于他缺乏经济头脑,所以先后聘请了若干个金融顾问为他设计经营方案. 题目描述 万事开头难,经营公司更是如此.开始的收益往往是很低的,不过随 ...

随机推荐

  1. tomcat https

    转自 http://11lingxian.iteye.com/blog/1491607 双向认证: 客户端向服务器发送消息,首先把消息用客户端证书加密然后连同时把客户端证书一起发送到服务器端, 服务器 ...

  2. GLSL in ShaderLab

    [Syntax] However, use of raw GLSL is only recommended for testing, or when you know you will only ta ...

  3. Kafka核心概念(转)

    转自:https://blog.csdn.net/liyiming2017/article/details/82805479 1.Kafka集群结构 实际上kafka的结构图是有些区别的,现在我们看下 ...

  4. tomcat使用log4j管理日志

    1.JDK+tomcat环境  参考:http://www.cnblogs.com/zzzhfo/p/6444029.html 2.下载相关软件 log4j下载地址 http://www.apache ...

  5. spring4-2-bean配置-9-通过工厂方法配置bean

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAAFICAIAAADbNrOHAAAgAElEQVR4nO2dy7W0uhGFOxWn4JEXAS

  6. mybaties association 只返回一个结果问题处理

    mybatis xml文件为: <resultMap id="BaseResultMap" type="com.test.SubscribeOrder"& ...

  7. 面向对象的JavaScript-006-Function.prototype.apply()的3种作用

    1. // Function.prototype.apply()的作用 // 1.Using apply to chain constructors Function.prototype.constr ...

  8. [C++] printf pitfall

    printf pitfal l

  9. 根据dateutil计算从前到现在过去多少时间

    import datetime from dateutil import relativedelta while 1: birthday = input(">>>" ...

  10. HDU 6127 Hard challenge (极角扫描)

    题意:给定 n 个点,和权值,他们两两相连,每条边的权值就是他们两个点权值的乘积,任意两点之间的直线不经过原点,让你从原点划一条直线,使得经过的直线的权值和最大. 析:直接进行极角扫描,从水平,然后旋 ...