[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 ...
随机推荐
- 一个极为简单的requirejs实现
require和 sea的源码分析,我之前的博客有写过, 今天我想分享的是一个很简单的核心代码(不带注释和空行大概60行), 没有容错判断. require.js require函数实现用一句话概括: ...
- 从底层带你理解Python中的一些内部机制
下面博文将带你创建一个字节码级别的追踪API以追踪Python的一些内部机制,比如类似YIELDVALUE.YIELDFROM操作码的实现,推式构造列表(List Comprehensions).生成 ...
- AndroidStudio0.5.5发布
Google%E5%9C%A8%E5%BC%80%E6%BA%90%E4%B8%8A%E7%9A%84%E8%B4%A1%E7%8C%AE http://music.baidu.com/songlis ...
- tcp四次撒手
转自:http://www.cnblogs.com/cy568searchx/p/3711670.html 由于TCP连接是全双工的,因此每个方向都必须单独进行关闭.这个原则是当一方完成它的数据发送任 ...
- 关于debian配置的问题汇总
debian的apache多域名配置: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-ho ...
- Football Games(思维题)
Problem Description A mysterious country will hold a football world championships---Abnormal Cup, at ...
- 详细解析@Resource和@Autowired的区别 , 以及@Qualifier的作用
(41) (0) 首先 . @Resource是javax.annotation 包中的注解类 , 是jdk中封装的 . @AutoWired是spring的中注解,依赖于spring上下文. 相同 ...
- elasticsearch this is not a http port
访问的是elastic search的tcp端口,需换成http端口. elastic search默认tcp端口9300,http端口9200 如果浏览器中访问http://localhost:92 ...
- [CCF] 201612-2 工资计算
[思路]按照题意对初始工资S进行循环,计算缴税后工资,若与T相等则退出循环,输出结果. #include <iostream> #include <windows.h> usi ...
- Hibernate关联映射之_一对多
domain: package org.zln.hibernate.domain; import java.util.Set; /** * 部门Domain对象 * Created by sherry ...