1568: [JSOI2008]Blue Mary开公司(超哥线段树)
1568: [JSOI2008]Blue Mary开公司
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 1198 Solved: 418
Description

Input
Output
Sample Input
Project 5.10200 0.65000
Project 2.76200 1.43000
Query 4
Query 2
Project 3.80200 1.17000
Query 2
Query 3
Query 1
Project 4.58200 0.91000
Project 5.36200 0.39000
Sample Output
0
0
0
0
HINT
Source
分析
超哥线段树,记录每个点的最大的线段是谁。查询时用这条线段查询。
那么怎么记录呢,(当时这个问题困惑我好久),线段树只能记录一段区间,对于一条线段它只记录一段区间,怎么保存区间所有的线段?
借用一张图说明这一点。
对于原来的区间[l,r]表示y'这条线段,就是让[l,r]区间的所有的线段是y',然后来了一条线段y”,显然在x点右边,y”要比y’更优,但是线段树只能从中间劈开,不能[l,x][x,r]这样,所以我们就找到中点mid = (l+r)/2,这样[mid,r]这段区间可以直接更新了,左区间继续像这样分,全部都更新完就好了。

code
#include<cstdio>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 using namespace std; const int MAXN = ;
int fut[MAXN<<];
double a[MAXN<<],b[MAXN<<];
char opt[];
int tot; int pd(int x,int y,int p)
{
return a[x]+(p-)*b[x] > a[y]+(p-)*b[y];
}
void update(int l,int r,int rt,int x)
{
if (l==r)
{
if (pd(x,fut[rt],l)) fut[rt] = x;
return ;
}
int m = (l+r)>>;
if (b[x]>b[fut[rt]])
{
if (pd(x,fut[rt],m)) update(lson,fut[rt]), fut[rt] = x;
else update(rson,x);
}
if (b[x]<b[fut[rt]])
{
if (pd(x,fut[rt],m)) update(rson,fut[rt]), fut[rt] = x;
else update(lson,x);
}
}
double getans(int k,int x)
{
return a[k]+(x-)*b[k];
}
double query(int l,int r,int rt,int x)
{
if (l==r) return getans(fut[rt],x);
int m = (l+r)>>;
double ans = getans(fut[rt],x);
if (x<=m) ans = max(ans,query(lson,x));
else ans = max(ans,query(rson,x));
return ans;
}
int main()
{
int n,x;
scanf("%d",&n);
for (int i=; i<=n; ++i)
{
scanf("%s",opt);
if (opt[]=='P')
{
++tot;
scanf("%lf%lf",&a[tot],&b[tot]);
update(,n,,tot);
}
else
{
scanf("%d",&x);
double t1 = query(,n,,x);
int t2 = t1;
printf("%d\n",t2/);
}
}
return ;
}
1568: [JSOI2008]Blue Mary开公司(超哥线段树)的更多相关文章
- bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树
[JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1808 Solved: 639[Submit][Sta ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)
[BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...
- 洛谷P4254 [JSOI2008]Blue Mary开公司(李超线段树)
题面 传送门 题解 李超线段树板子 具体可以看这里 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a ...
- 【洛谷 P4254】 [JSOI2008]Blue Mary开公司(李超线段树)
题目链接 其实这东西很好懂的..用来维护一次函数. 每个结点存一个值,表示x=这个区间的mid时值最大的函数的编号. 把插入线段的斜率和当前结点的斜率和大小比较来更新左右儿子的值. 查询是实际上是查询 ...
- 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 602 Solved: 214[Submit ...
- [BZOJ 1568][JSOI2008]Blue Mary开公司
[BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...
- 1568: [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...
- BZOJ.1568.[JSOI2008]Blue Mary开公司(李超线段树)
题目链接 线段树每个节点记录\(f(mid)\)最大的直线(在\(mid\)处函数值最大的直线),称作优势线段(还是直线啊...无所谓了). 如果是在区间插入线段会影响\(O(\log n)\)个区间 ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
随机推荐
- JAVA 面试重点知识个人总结
一.集合: 1 .Collection(是java.util下的接口) 和 Collections(是java.util下的类). 2 .List, Set,是否继承自Collection接口,Map ...
- agc015F - Kenus the Ancient Greek(结论题)
题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...
- 第2章 TCP-IP的工作方式
第2章 TCP-IP的工作方式 TCP/IP协议系统 为了实现TCP的功能,TCP/IP的创建者使用了模块化的设计.TCP/IP协议系统被分为不同的组件,每个组件分别负责通信过程的一个步骤.这种模块化 ...
- Counting blessings can actually increase happiness and health by reminding us of the good things in life.
Counting blessings can actually increase happiness and health by reminding us of the good things in ...
- python基础-三元运算和bytes数据
三元运算 进制 二进制,01 八进制,01234567 十进制,0123456789 十六进制,0123456789ABCDEF bytes类型 http://www.cnblogs. ...
- uvm_port_base——TLM1事务级建模方法(五)
文件: src/tlm1/uvm_port_base.svh 类: uvm_port_base uvm_port_component_base派生自uvm_component,因此具有其所有特性.提供 ...
- COGS 898. [咲 -Saki-] 天才麻将少女什么编
★☆ 输入文件:sakinani.in 输出文件:sakinani.out 简单对比时间限制:1 s 内存限制:256 MB 题目背景 二十一世纪,世界上的麻将竞技人数超过一亿,日本每 ...
- ImportError: No module named PIL
解决方法: 在C:\Python27\Scripts目录下打开命令行,输入: pip install Pillow
- POJ 3666 Making the Grade(区间dp)
修改序列变成非递减序列,使得目标函数最小.(这题数据有问题,只要求非递减 从左往右考虑,当前a[i]≥前一个数的取值,当固定前一个数的取值的时候我们希望前面操作的花费尽量小. 所以状态可以定义为dp[ ...
- 手机上如何远程控制Linux服务器?
这里介绍3个手机软件,分别是JuiceSSH.Termius和Termux,这3个软件都可以实现远程控制Linux服务器(相当于手机SSH客户端),而且使用起来都非常方便,下面我简单介绍一下这3个软件 ...