Blue Mary开公司
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开公司的更多相关文章
- 【BZOJ-1568】Blue Mary开公司 李超线段树 (标记永久化)
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 557 Solved: 192[Submit ...
- 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 602 Solved: 214[Submit ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)
[BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...
- [BZOJ 1568][JSOI2008]Blue Mary开公司
[BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树
[BZOJ1568][JSOI2008]Blue Mary开公司 Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词“Query”或“P ...
- 1568: [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...
- bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树
[JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1808 Solved: 639[Submit][Sta ...
- 1568: [JSOI2008]Blue Mary开公司(超哥线段树)
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1198 Solved: 418 Descr ...
- [Luogu] P4254 [JSOI2008]Blue Mary开公司
题目背景 Blue Mary 最近在筹备开一家自己的网络公司.由于他缺乏经济头脑,所以先后聘请了若干个金融顾问为他设计经营方案. 题目描述 万事开头难,经营公司更是如此.开始的收益往往是很低的,不过随 ...
随机推荐
- Python3 Scrapy 框架学习
1.安装scrapy 框架 windows 打开cmd输入 pip install Scrapy 2.新建一个项目: 比如这里我新建的项目名为first scrapy startproject fir ...
- WEB入门——信息搜集1-20
WEB1--查看源码 查看源码即可得flag. WEB2--JS前端禁用 查看源码即可得flag. JavaScript实现禁用的方法简单来说就是当用户使用键盘执行某一命令是返回的一种状态,而这种状态 ...
- 《浅谈亚 log 数据结构在 OI 中的应用》阅读随笔
这篇又长长长了! \(8435\to 8375\to 9729\) 早就馋这篇了!终于学了( 压位 Trie 确实很好写啊 但是总感觉使用范围不是很广的样子 似乎是见的题少 原文里都在用 \(\log ...
- Fastjson漏洞+复现
1.漏洞介绍 FastJson在解析json的过程中,支持使用autoType来实例化某一个具体的类,并调用该类的set/get方法来访问属性.通过查找代码中相关的方法,即可构造出一些恶意利用链. ...
- 4.10:Spark之wordcount
〇.概述 1.拓扑结构 2.目标 使用spark完成计数实验 一.启动环境 二.新建数据文件 三.查看文件内容 四.启动spark服务 五.编写代码 复制以下代码到shell中(复制后在终端右键-&g ...
- 一个小时,200行代码,手写Spring的IOC、DI、MVC
一.概述 配置阶段:主要是完成application.xml配置和Annotation配置. 初始化阶段:主要是加载并解析配置信息,然后,初始化IOC容器,完成容器的DI操作,已经完成HandlerM ...
- Springboot优雅进行字段检验
Springboot优雅进行字段检验 1.Controller VS Service 推荐与业务无关的放在controller层中进行校验,而与业务相关的放在service层中校验. 2.常用校验工具 ...
- 论文翻译:2022_DNS_1th:Multi-scale temporal frequency convolutional network with axial attention for speech enhancement
论文地址:带轴向注意的多尺度时域频率卷积网络语音增强 论文代码:https://github.com/echocatzh/MTFAA-Net 引用:Zhang G, Yu L, Wang C, et ...
- python 之异常捕获及处理(try--except)
在python中,至少有两类错误,一种是程序语法错误,一种是程序异常. 所谓的语法错误是指你未按规定格式书写导致的错误,如:定义函数时,括号后面要紧跟英文冒号,若缺失则不能识别与运行,并抛出 Synt ...
- RuntimeError: setuptools >= 41 required to build
使用命令python setup.py install 安装第三方库报RuntimeError: setuptools >= 41 required to build 原因setuptools版 ...