[bzoj1568][JSOI2008]Blue Mary开公司——李超线段树
题目大意
题解
这道题需要用到一种叫做李超线段树的东西。我对于李超线段树,是这样理解的:
给节点打下的标记不进行下传,而是仅仅在需要的时候进行下传,这就是所谓永久化标记。
对于这道题,借用一张图,
这张图解释的比较清楚了。
代码
#include <algorithm>
#include <cctype>
#include <cstdio>
int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int N, M;
struct line {
double k, b;
int id;
double getf(int x) { return k * x + b; };
};
bool cmp(line a, line b, int x) {
if (!a.id)
return 1;
return a.getf(x) != b.getf(x) ? a.getf(x) < b.getf(x) : a.id < b.id;
}
const int maxn = 50010;
line t[maxn << 2];
line query(int k, int l, int r, int x) {
if (l == r)
return t[k];
int mid = (l + r) >> 1;
line tmp;
if (x <= mid)
tmp = query(k << 1, l, mid, x);
else
tmp = query(k << 1 | 1, mid + 1, r, x);
return cmp(t[k], tmp, x) ? tmp : t[k];
}
void insert(int k, int l, int r, line x) {
if (!t[k].id)
t[k] = x;
if (cmp(t[k], x, l))
std::swap(t[k], x);
if (l == r || t[k].k == x.k)
return;
int mid = (l + r) >> 1;
double X = (t[k].b - x.b) / (x.k - t[k].k);
if (X < l || X > r)
return;
if (X <= mid)
insert(k << 1, l, mid, t[k]), t[k] = x;
else
insert(k << 1 | 1, mid + 1, r, x);
}
void Insert(int k, int l, int r, int x, int y, line v) {
if (x <= l && r <= y) {
insert(k, l, r, v);
return;
}
int mid = (l + r) >> 1;
if (x <= mid)
Insert(k << 1, l, mid, x, y, v);
if (y > mid)
Insert(k << 1 | 1, mid + 1, r, x, y, v);
}
int main() {
#ifdef D
freopen("input", "r", stdin);
#endif
M = read();
N = 50000;
char opt[15];
while (M--) {
scanf("%s", opt);
if (opt[0] == 'P') {
double k, b;
scanf("%lf %lf", &k, &b);
line tmp;
tmp.k = b;
tmp.b = k - b;
tmp.id = 1;
Insert(1, 1, N, 1, N, tmp);
}
int x;
if (opt[0] == 'Q') {
x = read();
printf("%lld\n", (long long)(query(1, 1, N, x).getf(x) / 100 + 1e-8));
}
}
return 0;
}
[bzoj1568][JSOI2008]Blue Mary开公司——李超线段树的更多相关文章
- 【BZOJ-1568】Blue Mary开公司 李超线段树 (标记永久化)
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 557 Solved: 192[Submit ...
- 2019.02.11 bzoj1568: [JSOI2008]Blue Mary开公司(线段树)
传送门 题意简述:维护整体加一条线段,求单点极值. 思路: 直接上李超线段树维护即可. 代码: #include<bits/stdc++.h> #define ri register in ...
- JSOI2008 Blue Mary开公司 | 李超线段树学习笔记
题目链接:戳我 这相当于是一个李超线段树的模板qwqwq,题解就不多说了. 代码如下: #include<iostream> #include<cstdio> #include ...
- BZOJ.1568.[JSOI2008]Blue Mary开公司(李超线段树)
题目链接 线段树每个节点记录\(f(mid)\)最大的直线(在\(mid\)处函数值最大的直线),称作优势线段(还是直线啊...无所谓了). 如果是在区间插入线段会影响\(O(\log n)\)个区间 ...
- [JSOI2008]Blue Mary开公司[李超线段树]
题面 bzoj luogu 好久以前听lxl讲过 咕掉了.. 竟然又遇到了 安利blog #include <cmath> #include <cstring> #includ ...
- BZOJ-1568: Blue Mary开公司 (李超线段树)
Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词“Query”或“Project”. 若单词为Query,则后接一个整数T,表示Blue ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
- BZOJ1568: [JSOI2008]Blue Mary开公司
可以平衡树或线段树维护斜率来做. 还有一种线段树直接打标记的做法: 线段树每个节点存一条线段作为标记,打标记时如果已有标记,则把占优区间小的那个线段下放. #include<cstdio> ...
- BZOJ1568: [JSOI2008]Blue Mary开公司【李超树】
Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词"Query"或"Project". 若单词为Q ...
随机推荐
- Java Swing 图形界面开发(目录)
Java Swing 图形界面开发(目录) 2017年05月30日 23:50:42 阅读数:5228 本文链接: http://blog.csdn.net/xietansheng/article/d ...
- jenkins安全内容配置策略
有时我们使用HTML Publisher Plugin插件时,在jenkins点开html report,会发现没有带任何的css或js样式,这是因为Jenkins 1.641 / Jenkins 1 ...
- 实现一个简单版的express
express应该算是早期最优秀的一个node框架了,刚开始学node做后端语言就是用的express,它的cli可以帮我们搭建好项目目录,就像现在的vue,react一样.express本身没有做太 ...
- 今日Linux
一.复习了vi 三个模式下的一些操作.贴上一些比较常用,个人觉得比较难记的操作.1.一般模式:h 光标向左移动一个字符j 光标向下移动一个字符K 光标向上移动一个字符l 光标向右移动一个 ...
- python学习总结----简单数据结构
mini-web服务器 - 能够完成简单的请求处理 - 使用http协议 - 目的:加深对网络编程的认识.为后面阶段学习web做铺垫 简单数据结构 - 排列组合 import itertools # ...
- JVM 什么时候会触发FGC
1:System.gc(); 2:老年代满了 没啥好说的从年轻代去往老年代的 3:JDK7或JDK6中永久区满了 得看是否还会有分配,如果没有就不会进行FGC,不过CMS GC下会看到不停地CMS G ...
- Pro Git - 笔记2
Git Basics Getting a Git Repository Initializing a Repository in an Existing Directory For Linux: $ ...
- 并查集——hdu1232(入门)
传送门:畅通工程 实质是求连通分支的数量 #include <iostream> #include <cstdio> #include <algorithm> us ...
- lintcode-52-下一个排列
52-下一个排列 给定一个整数数组来表示排列,找出其之后的一个排列. 注意事项 排列中可能包含重复的整数 样例 给出排列[1,3,2,3],其下一个排列是[1,3,3,2] 给出排列[4,3,2,1] ...
- SQL Server 性能调优 之执行计划(Execution Plan)调优
SQL Server 存在三种 Join 策略:Hash Join,Merge Join,Nested Loop Join. Hash Join:用来处理没有排过序/没有索引的数据,它在内存中把 Jo ...