BZOJ 1568

学习了一波李超线段树。

大佬blog

这个东西专门用来维护插入一条线段和区间/单点的最大/最小值。

插入的时候讨论:

1、如果当前结点上没有线段,那么直接插入。

2、如果当前结点上的线段一定比要插入的线段优/劣,那么直接覆盖或者返回。

3、如果当前结点上的线段和要插入的线段有交点,那么把优的部分比劣的部分多的线段放在当前结点上,然后把另一条线段下放给那个交点所在的儿子递归处理。

时间复杂度$O(nlogn)$,但是有返回这个操作看上去就很快……

Code:

#include <cstdio>
#include <cstring>
using namespace std;
typedef double db;
typedef long long ll; const int N = 5e4 + ; int n = (int)5e4, qn; template <typename T>
inline void chkMax(T &x, T y) {
if(y > x) x = y;
} namespace SegT {
struct Node {
db lb, lk;
bool cov;
} s[N << ]; #define lc p << 1
#define rc p << 1 | 1
#define mid ((l + r) >> 1)
#define lb s[p].lb
#define lk s[p].lk
#define cov s[p].cov void ins(int p, int l, int r, db b, db k) {
if(!cov) {
lb = b, lk = k, cov = ;
return;
} db l1 = 1.0 * l * k + b, r1 = 1.0 * r * k + b;
db l2 = 1.0 * l * lk + lb, r2 = 1.0 * r * lk + lb; if(l1 >= l2 && r1 >= r2) {
lb = b, lk = k;
return;
}
if(l1 <= l2 && r1 <= r2) return; db x = (b - lb) / (lk - k);
if(l1 > l2) {
if(x > mid) ins(rc, mid + , r, lb, lk), lb = b, lk = k;
else ins(lc, l, mid, b, k);
} else {
/* if(x <= mid) ins(lc, l, mid, lb, lk), lb = b, lk = k;
else ins(rc, mid + 1, r, lb, lk); */
if(x > mid) ins(rc, mid + , r, b, k);
else ins(lc, l, mid, lb, lk), lb = b, lk = k;
}
} db query(int p, int l, int r, int x) {
if(l == r) return lk * x + lb;
db res = lk * x + lb;
if(x <= mid) chkMax(res, query(lc, l, mid, x));
else chkMax(res, query(rc, mid + , r, x));
return res;
} } using namespace SegT; int main() {
scanf("%d", &qn);
for(char op[]; qn--; ) {
scanf("%s", op);
if(op[] == 'P') {
db b, k;
scanf("%lf%lf", &b, &k);
b -= k;
ins(, , n, b, k);
} else {
int x; scanf("%d", &x);
db ans = query(, , n, x);
printf("%lld\n", (ll) (ans / 100.0));
}
}
return ;
}

Luogu 4254 [JSOI2008]Blue Mary开公司的更多相关文章

  1. [Luogu] P4254 [JSOI2008]Blue Mary开公司

    题目背景 Blue Mary 最近在筹备开一家自己的网络公司.由于他缺乏经济头脑,所以先后聘请了若干个金融顾问为他设计经营方案. 题目描述 万事开头难,经营公司更是如此.开始的收益往往是很低的,不过随 ...

  2. 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司

    1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 602  Solved: 214[Submit ...

  3. bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司

    http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...

  4. 【BZOJ1568】[JSOI2008]Blue Mary开公司(李超线段树)

    [BZOJ1568][JSOI2008]Blue Mary开公司(李超线段树) 题面 BZOJ 洛谷 题解 是模板题啊. #include<iostream> #include<cs ...

  5. [BZOJ 1568][JSOI2008]Blue Mary开公司

    [BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...

  6. 【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树

    [BZOJ1568][JSOI2008]Blue Mary开公司 Description Input 第一行 :一个整数N ,表示方案和询问的总数.  接下来N行,每行开头一个单词“Query”或“P ...

  7. 1568: [JSOI2008]Blue Mary开公司

    1568: [JSOI2008]Blue Mary开公司 题目描述 传送门 题目分析 简单分析可以发现就是不停给出了\(n\)条直线,要求每次给出一条直线后求出所有直线在横坐标为\(x\)时\(y\) ...

  8. bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树

    [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1808  Solved: 639[Submit][Sta ...

  9. 1568: [JSOI2008]Blue Mary开公司(超哥线段树)

    1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1198  Solved: 418 Descr ...

随机推荐

  1. opencv之图像滤波

    均值滤波 均值滤波函数cv2.blur() import cv2 img = cv2.imread('01.jpg') blur = cv2.blur(img,(5,5)) cv2.imshow(&q ...

  2. H5打字机特效

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Spring aop 简单示例

    简单的记录一下spring aop的一个示例 基于两种配置方式: 基于xml配置 基于注解配置 这个例子是模拟对数据库的更改操作添加事物 其实并没有添加,只是简单的输出了一下记录 首先看下整个例子的目 ...

  4. Bundle的使用

    a.Activity1发送: Intent intent = new Intent();   intent.setClass(activity1.this, activity2.class);   / ...

  5. 支付宝sdk集成

    支付宝开放平台 http://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103563&docType=1 集成步骤: 1. ...

  6. shell中的输入输出和编程中的变量(shell 03)

    shell中的输入输出标准输入:键盘标准输出:终端显示器>> 追加是换行追加的echo -n 不尾随换行符 -e 启用解释反斜杠的转义功能 -E 禁用解释反斜杠的转义功能(默认) --he ...

  7. 数据流重定向和管道命令, grep, tr,sort, wc, cut,split,tee,sleep(shell 02)

    主要内容 1.标准输入输出和错误 2.管道命令和 grep, tr,sort, wc, cut,split,tee,sleep 标准输入输出和错误 标准输入(stdin) 是指令数据的输入,代码为0, ...

  8. Vue.js:模版语法

    ylbtech-Vue.js:模版语法 1.返回顶部 1. Vue.js 模板语法 Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. Vu ...

  9. 类的特殊成员方法,类的起源type, metaclass

    1.__doc__表示类的描述信息 2. __module__ 和  __class__  __module__ 表示当前操作的对象在那个模块 __class__     表示当前操作的对象的类是什么 ...

  10. python's twenty-third day for me 面向对象进阶

    普通方法:对象和类绑定的过程. class A: def func1(self):pass def func2(self):pass def func3(self):pass def func4(se ...