Blue Mary开公司

题面:[JSOI2008]Blue Mary开公司

题目大意:

每次加入一条形如 \(y=Px + S - P\) 的直线,询问 \(x=T\) 时此处最高的 \(y\) 值(\(S,P,T\)均为题中给出)

思路

很经典的李超树模板, 每次在整个线段树中加入一条直线

注意:每天最小收益至少为 \(0\)!!

即你的答案必然不小于 \(0\) !!

不会李超树的戳这里:李超树学习笔记

\(Code\)

#include<cstdio>
#include<cmath>
using namespace std; const int T = 50010;
int n , fl[4 * T]; struct tree{
double k , b;
}seg[4 * T]; inline double max(double x , double y){return x < y ? y : x;}
inline double Intersection(double k1 , double b1 , double k2 , double b2){return 1.0 * (b2 - b1) / (k1 - k2);} inline void update(double k , double b , int l , int r , int rt)
{
if (!fl[rt])
{
seg[rt].k = k , seg[rt].b = b , fl[rt] = 1;
return;
}
double f1 = seg[rt].k * l + seg[rt].b , f2 = seg[rt].k * r + seg[rt].b;
double f3 = k * l + b , f4 = k * r + b;
if (f1 >= f3 && f2 >= f4) return;
else if (f1 <= f3 && f2 <= f4) seg[rt].k = k , seg[rt].b = b;
else{
int mid = (l + r) >> 1;
double len = Intersection(k , b , seg[rt].k , seg[rt].b);
if (f1 <= f3)
{
if (len <= mid) update(k , b , l , mid , rt << 1);
else update(seg[rt].k , seg[rt].b , mid + 1 , r , rt << 1 | 1) , seg[rt].k = k , seg[rt].b = b;
}
else {
if (len > mid) update(k , b , mid + 1 , r , rt << 1 | 1);
else update(seg[rt].k , seg[rt].b , l , mid , rt << 1) , seg[rt].k = k , seg[rt].b = b;
}
}
} inline double query(int l , int r , int rt , int x)
{
double ans = 1.0 * seg[rt].k * x + seg[rt].b;
if (l == r) return ans;
int mid = (l + r) >> 1;
if (x <= mid) ans = max(ans , query(l , mid , rt << 1 , x));
else ans = max(ans , query(mid + 1 , r , rt << 1 | 1 , x));
return ans;
} int main()
{
char s[10];
double b , k;
int x;
scanf("%d" , &n);
for(register int i = 1; i <= 4 * 50005 + 1; i++) seg[i].b = -1e18 , seg[i].k = 0;
while(n--)
{
scanf("%s" , s + 1);
if (s[1] == 'P')
{
scanf("%lf %lf" , &b , &k);
b = b - k;
update(k , b , 1 , 5e4 + 5 , 1);
}
else {
scanf("%d" , &x);
double ans = query(1 , 5e4 + 5 , 1 , x);
if (ans <= 0) printf("0\n");
else printf("%d\n" , (int)(ans / 100));
}
}
}

Blue Mary开公司的更多相关文章

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

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

  2. 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司

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

  3. bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司

    http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...

  4. 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)

    [BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...

  5. [BZOJ 1568][JSOI2008]Blue Mary开公司

    [BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...

  6. 【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树

    [BZOJ1568][JSOI2008]Blue Mary开公司 Description Input 第一行 :一个整数N ,表示方案和询问的总数.  接下来N行,每行开头一个单词“Query”或“P ...

  7. 1568: [JSOI2008]Blue Mary开公司

    1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...

  8. bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树

    [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1808  Solved: 639[Submit][Sta ...

  9. 1568: [JSOI2008]Blue Mary开公司(超哥线段树)

    1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1198  Solved: 418 Descr ...

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

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

随机推荐

  1. conky配置(附配置项作用解释)

    alignment top_right #是否嵌入桌面 background yes #是否绘制窗口边框 draw_borders no #窗口边框 border_width 10 #cpu_avg_ ...

  2. Android ViewPager2 + Fragment + BottomNavigationView 联动

    Android ViewPager2 + Fragment + BottomNavigationView 联动 本篇主要介绍一下 ViewPager2 + Fragment + BottomNavig ...

  3. [论文阅读] 颜色迁移-Linear Monge-Kantorovitch(MKL)

    [论文阅读] 颜色迁移-Linear Monge-Kantorovitch(MKL) 文章: The Linear Monge-Kantorovitch Linear Colour Mapping f ...

  4. mac连接mysql出现Access denied for user ‘root‘@‘localhost‘

    处理方法:1.关闭mysql的服务,点击最左上的苹果图标在系统偏好设置中,找到mysql,点击,stop 确认关闭后进入终端 输入(cd /usr/local/mysql/bin/)回车 输入(sud ...

  5. 万字干货|Synchronized关键字详解

    作者:小牛呼噜噜 | https://xiaoniuhululu.com 计算机内功.JAVA底层.面试.职业成长相关资料等更多精彩文章在公众号「小牛呼噜噜」 前言 大家好,我是呼噜噜,在之前的文章中 ...

  6. React报错之Function components cannot have string refs

    总览 当我们在一个函数组件中使用一个字符串作为ref时,会产生"Function components cannot have string refs"错误.为了解决该错误,使用u ...

  7. YonBuilder移动开发平台功能大盘点

    YonBuilder是面向企业组织和个人开发者的低代码开发平台,实现无代码.低代码.专业代码开发三种模式.提供元数据驱动和画布构建两种开发方式,通过点击拖拽+自动化代码生成和移动多端编译的技术,与开放 ...

  8. uniapp微信小程序 下拉刷新(上拉请求下一页数据)

    <template>标签中: <view class="" v-if="daShow==1"> <view class=" ...

  9. 16、SQL操作JSON字段

    Mysql5.7版本以后提供一个原生的Json类型,Json值将不再以字符串的形式存储,而是采用一种允许快速读取文本元素(document elements)的内部二进制(internal binar ...

  10. s2-005

    漏洞名称 (CVE-2010-1870) - XWork ParameterInterceptors旁路允许远程命令执行 利用条件 Struts 2.0.0 - Struts 2.1.8.1 漏洞原理 ...