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 最近在筹备开一家自己的网络公司.由于他缺乏经济头脑,所以先后聘请了若干个金融顾问为他设计经营方案. 题目描述 万事开头难,经营公司更是如此.开始的收益往往是很低的,不过随 ...
随机推荐
- NLP手札1. 金融信息负面及主体判定方案梳理&代码实现
这个系列会针对NLP比赛,经典问题的解决方案进行梳理并给出代码复现~也算是找个理由把代码从TF搬运到torch.Chapter1是CCF BDC2019的赛题:金融信息负面及主体判定,属于实体关联的情 ...
- ajax 获取json值
请求后台获取json: {"success":true,"datamap":{"rebackName":"振勋"}} a ...
- Linux 基础-文件权限与属性
一,文件类型 1.1,概述 1.2,正规文件(regular file) 1.3,目录(directory) 1.4,链接文件(link) 1.5,设备与装置文件(device) 1.6,资料接口文件 ...
- 【Java EE】Day04 MySQL多表、事务、事务隔离级别、DCL
一.多表查询 1.概述 笛卡尔积:两集合的所有组成情况 多表查询:消除笛卡尔积得到的无用数据 2.分类 内连接查询(满足指定条件无空值,只显示有关联的数据) 隐式内连接:使用where限制消除无用数据 ...
- 【RocketMQ】主从同步实现原理
主从同步的实现逻辑主要在HAService中,在DefaultMessageStore的构造函数中,对HAService进行了实例化,并在start方法中,启动了HAService: public c ...
- 使用selenium爬取淘宝
一.出现的问题 前段时间在使用selenium对淘宝进行模拟登陆的时候,输入完正好和密码,然后验证码无论如何都不能划过去.找了好久,原来是因为selenium在浏览器中运 行的时候会暴露 ...
- jQuery类库
jQuery介绍 1. jQuery是一个轻量级的.兼容多浏览器的JavaScript库. 2. jQuery使用户能够更方便地处理HTML Document.Events.实现动画效果.方便地进行A ...
- 事件 jQuery类库、Bootstrap页面框架
目录 jQuery查找标签 基本选择器 组合选择器 层级选择器 属性选择器 基本筛选器 表单筛选器 筛选器方法 链式的本质(jQuery一行代码走天下) 操作标签 class操作 位置操作 文本操作 ...
- [数据与分析可视化] D3入门教程1-d3基础知识
d3.js入门教程1-d3基础知识 文章目录 d3.js入门教程1-d3基础知识 1 HTML介绍 1.1 什么是HTML? 1.2 自定义文档样式CSS 1.3 构建svg图形 2 d3绘图入门 2 ...
- S2-017 CVE-2013-2248
漏洞名称 Apache Struts 多个开放重定向漏洞 (CVE-2013-2248) s2-017 利用条件 Struts 2.0.0 - Struts 2.3.15 漏洞原理 通过操作前缀为&q ...