bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树
[JSOI2008]Blue Mary开公司
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 1808 Solved: 639
[Submit][Status][Discuss]
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
题解:可以看出许多条一次函数,然后每次询问的时候就是求一个x的坐标的答
案,超哥线段树可以说就是永久标记维护各段的最大值。
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<map> #define N 50007
#define ls p<<1
#define rs p<<1|1
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,tot;
double ans;
int tr[N<<];
char ch[];
struct Node
{
double k,b;
}a[N<<]; bool judge(int x,int y,int t)
{
t--;
return a[x].b+a[x].k*t>a[y].b+a[y].k*t;
}
void ins(int p,int l,int r,int x)
{
if (l==r)
{
if (judge(x,tr[p],l)) tr[p]=x;
return;
}
int mid=(l+r)>>;
if (a[x].k>a[tr[p]].k)
{
if (judge(x,tr[p],mid)) ins(ls,l,mid,tr[p]),tr[p]=x;
else ins(rs,mid+,r,x);
}
else
{
if (judge(x,tr[p],mid)) ins(rs,mid+,r,tr[p]),tr[p]=x;
else ins(ls,l,mid,x);
}
}
void query(int p,int l,int r,int x)
{
ans=max(ans,a[tr[p]].k*(x-)+a[tr[p]].b);
if (l==r) return;
int mid=(l+r)>>;
if (x<=mid) query(ls,l,mid,x);
else query(rs,mid+,r,x);
}
int main()
{
n=read();
for (int i=;i<=n;i++)
{
scanf("%s",ch);
if (ch[]=='P')
{
tot++;
scanf("%lf%lf",&a[tot].b,&a[tot].k);
ins(,,n,tot);
}
else
{
ans=;query(,,n,read());
printf("%d\n",(int)ans/);
}
}
}
bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树的更多相关文章
- [BZOJ 1568][JSOI2008]Blue Mary开公司
[BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...
- 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)
[BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...
- 数据结构(线段树):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开公司(李超线段树)
题目链接 线段树每个节点记录\(f(mid)\)最大的直线(在\(mid\)处函数值最大的直线),称作优势线段(还是直线啊...无所谓了). 如果是在区间插入线段会影响\(O(\log n)\)个区间 ...
- 洛谷P4254 [JSOI2008]Blue Mary开公司(李超线段树)
题面 传送门 题解 李超线段树板子 具体可以看这里 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a ...
- 【洛谷 P4254】 [JSOI2008]Blue Mary开公司(李超线段树)
题目链接 其实这东西很好懂的..用来维护一次函数. 每个结点存一个值,表示x=这个区间的mid时值最大的函数的编号. 把插入线段的斜率和当前结点的斜率和大小比较来更新左右儿子的值. 查询是实际上是查询 ...
- 1568: [JSOI2008]Blue Mary开公司(超哥线段树)
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1198 Solved: 418 Descr ...
- 1568: [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
随机推荐
- String和StringBuffer以及StringBuilder的区别
今天在读<java编程思想>的时间,在看到String和StringBuffer以及StringBuffer这三个类的时间,做一个随笔小结,为自己的面试做好准备! 一:String,Str ...
- smartgit 使用
合并分支
- HPUX 11.31 MC/SG恢复丢失的锁盘
有时候由于一些特殊的原因,用户的cluster中的锁盘信息丢失,或者需要更换锁盘,只要执行一个命令就可以了. #cmdisklock reset /dev/vglock:/dev/disk/diskX ...
- [递推+矩阵快速幂]Codeforces 1117D - Magic Gems
传送门:Educational Codeforces Round 60 – D 题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem ...
- MATLAB画图符号标注
线型 说明 标记符 说明 颜色 说明 - 实线(默认) + 加号符 r 红色 -- 双划线 o 空心圆 g 绿色 : 虚线 * 星号 b 蓝色 :. 点划线 . 实心圆 c 青绿色 x 叉号符 m 洋 ...
- POJ 2540 Hotter Colder(半平面交)
Description The children's game Hotter Colder is played as follows. Player A leaves the room while p ...
- MySQL用户管理及权限管理
MySQL 默认有个root用户,但是这个用户权限太大,一般只在管理数据库时候才用.如果在项目中要连接 MySQL 数据库,则建议新建一个权限较小的用户来连接. 在 MySQL 命令行模式下输入如下命 ...
- java安装环境变量设置
1,依次打开:我的电脑-->属性-->高级-->环境变量 2,设置用户变量 新建 JAVA_HOME C:\Program Files\Java\j2sdk1.5.0 (JDK的安装 ...
- 将HTML页面页脚固定在页面底部(多种方法实现)
当一个HTML页面中含有较少的内容时,Web页面的footer部分随着飘上来,处在页面的半腰中间,给视觉效果带来极大的影响,接下来为大家介绍下如何将页脚固定在页面底部,感兴趣的朋友可以了解下 作为一个 ...
- LintCode-204.单例
单例 单例 是最为最常见的设计模式之一.对于任何时刻,如果某个类只存在且最多存在一个具体的实例,那么我们称这种设计> 模式为单例.例如,对于 class Mouse (不是动物的mouse哦), ...