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< ...
随机推荐
- bson文件的切分
描述 最近遇到问题需要将较大的bson文件(MongoDB导出的二进制json文件)按文档(记录)进行切分,网上这方面的资料实在太少,弄了一天多终于达到了基本要求(还不知道有没有BUG) 代码 pac ...
- java学习笔记-8.对象的容纳
1.Iterator(迭代器)和Enumeration(枚举类),都是用来遍历集合的,他们都是接口.区别是Enumeration只能读取集合的数据,而Iterator可以对数据进行删除,Iterato ...
- 使用Docker部署java web项目
在国内可能会有源下载失败问题,docker安装失败, 这里提供docker离线安装包如有需要可以进行下载 docker离线安装包下载 ##本文环境使用centos 7 进行部署. #1安装docker ...
- python作业:三级菜单(第一周)
一.作业需求: 1. 运行程序输出第一级菜单 2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单 3. 菜单数据保存在文件中 4. 让用户选择是否要退出 5. 有返回上一级菜单的功能 二.三级菜单 ...
- react创建新项目并且修改配置文件
react创建项目 这是我在用react搭建项目时,用到的一些东西,顺序纯属自己定义, 一.创建项目 用react 创建一个项目,这也是官方给出的 1.npm install create-react ...
- HDU 1403 Longest Common Substring(后缀自动机——附讲解 or 后缀数组)
Description Given two strings, you have to tell the length of the Longest Common Substring of them. ...
- php分页类的实现与调用 (自我摘记)
page.class.php <?php namespace Component; class Page { private $total; //数据表中总记录数 private $listRo ...
- mysql 启动报错
之前用我这个机器做mysql的测试来,今天启动准备搭建一套线上的主从,结果起不来了... 错误日志: ;InnoDB: End of page dump 170807 11:37:02 InnoDB: ...
- nginx虚拟目录实现两个后台使用
购买了阿里云机器,准备搭建一套备份的后台,由于资源有限所以将两个后台搭建到一组SLB下的两台WEB上. 使用软件:NGINX+PHP root@xx conf.d]# yum install php- ...
- Python-列表练习
1.使用列表生成式生成如下列表:[1,9,25,49,81] s = [i**2 for i in range(1,10)if i%2==1] print(s) 2.输入一个由英文单词组成的字符串(分 ...