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< ...
随机推荐
- spring java config 初探
Java Config 注解 spring java config作为同xml配置形式的另一种表达形式,使用的场景越来越多,在新版本的spring boot中 大量使用,今天我们来看下用到的主要注解有 ...
- SGU 438 The Glorious Karlutka River =)(最大流)
Description A group of Mtourists are walking along the Karlutka river. They want to cross the river, ...
- 《C++面试知识点》
[动态内存] 1. 由内置指针管理的动态内存(即new和delete管理动态内存),直到被显式释放之前它都是存在的.假设该指针变量被销毁,那该内存将不会自动释放(即所谓的“内存泄漏”). 2. 可以用 ...
- "Hello world!"团队第一次会议
今天是我们"Hello world!"团队第一次召开会议,今天的会议可能没有那么正式,但是我们一起确立了选题——基于WEB的售票系统.博客内容是: 1.会议时间 2.会议成员 3. ...
- Java之I/O流(第2部分)
1. 节点类类型: 2. 访问文件: Demo_1: import java.io.FileInputStream; import java.io.FileNotFoundException; imp ...
- Java中ArrayList与数组间相互转换
在实际的 Java 开发中,如何选择数据结构是一个非常重要的问题. 衡量标准化(读的效率与改的效率) : ① Array: 读快改慢 ② Linked :改快读慢 ③ Hash:介于两者之间 实现Li ...
- 一个demo让你彻底理解Android中触摸事件的分发
注:本文涉及的demo的地址:https://github.com/absfree/TouchDispatch 1. 触摸动作及事件序列 (1)触摸事件的动作 触摸动作一共有三种:ACTION_DOW ...
- <Android>spinner/AutoCompleteTextView绑定适配器
position = (Spinner)findViewById(R.id.position); String[] str = {"CEO","CFO",&qu ...
- MVC4+EF5 edmx代码分析
本文分析Entity Framework(EF)从数据库自动生成的模型文件代码(扩展名为edmx). 一. 概述 本文使用的数据库结构尽量简单,只有2个表,一个用户表和一个分公司表(相当于部门表),一 ...
- 【.NET】- async await 异步编程
为什么需要异步,异步对可能起阻止作用的活动(例如,应用程序访问 Web 时)至关重要. 对 Web 资源的访问有时很慢或会延迟. 如果此类活动在同步过程中受阻,则整个应用程序必须等待. 在异步过程中, ...