题目大意

题解

这道题需要用到一种叫做李超线段树的东西。我对于李超线段树,是这样理解的:

给节点打下的标记不进行下传,而是仅仅在需要的时候进行下传,这就是所谓永久化标记。

对于这道题,借用一张图,



这张图解释的比较清楚了。

代码

#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开公司——李超线段树的更多相关文章

  1. 【BZOJ-1568】Blue Mary开公司 李超线段树 (标记永久化)

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

  2. 2019.02.11 bzoj1568: [JSOI2008]Blue Mary开公司(线段树)

    传送门 题意简述:维护整体加一条线段,求单点极值. 思路: 直接上李超线段树维护即可. 代码: #include<bits/stdc++.h> #define ri register in ...

  3. JSOI2008 Blue Mary开公司 | 李超线段树学习笔记

    题目链接:戳我 这相当于是一个李超线段树的模板qwqwq,题解就不多说了. 代码如下: #include<iostream> #include<cstdio> #include ...

  4. BZOJ.1568.[JSOI2008]Blue Mary开公司(李超线段树)

    题目链接 线段树每个节点记录\(f(mid)\)最大的直线(在\(mid\)处函数值最大的直线),称作优势线段(还是直线啊...无所谓了). 如果是在区间插入线段会影响\(O(\log n)\)个区间 ...

  5. [JSOI2008]Blue Mary开公司[李超线段树]

    题面 bzoj luogu 好久以前听lxl讲过 咕掉了.. 竟然又遇到了 安利blog #include <cmath> #include <cstring> #includ ...

  6. BZOJ-1568: Blue Mary开公司 (李超线段树)

    Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词“Query”或“Project”. 若单词为Query,则后接一个整数T,表示Blue ...

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

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

  8. BZOJ1568: [JSOI2008]Blue Mary开公司

    可以平衡树或线段树维护斜率来做. 还有一种线段树直接打标记的做法: 线段树每个节点存一条线段作为标记,打标记时如果已有标记,则把占优区间小的那个线段下放. #include<cstdio> ...

  9. BZOJ1568: [JSOI2008]Blue Mary开公司【李超树】

    Description Input 第一行 :一个整数N ,表示方案和询问的总数. 接下来N行,每行开头一个单词"Query"或"Project". 若单词为Q ...

随机推荐

  1. 云计算之路-阿里云上:Web服务器请求到达量突降

    今天下午遇到了自使用阿里云以来首次遇到的新情况——http.sys的ArrivalRate突降(说明请求到达IIS的请求数量少了),而且SLB中的3台ECS都出现了这个问题. 1. 10.161.24 ...

  2. ABP框架设置默认语言

    在Global.asax文件中设置 private readonly IAbpWebLocalizationConfiguration _webLocalizationConfiguration; p ...

  3. django中判断当前user具有是否有对模块的增删改查权限

    首先简单了解一下user的一些属性 User对象 User对象是认证系统的核心.用户对象通常用来代表网站的用户,并支持例如访问控制.注册用户.关联创建者和内容等.在Django认证框架中只有一个用户类 ...

  4. python中locals和globals函数

    参考:http://www.cnblogs.com/wanxsb/archive/2013/05/07/3064783.html Python有两个内置的函数,locals() 和globals(), ...

  5. Cache的封装和使用

    ICache 接口 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  6. PE文件格式介绍

    Useful Tools: 1. WDK安装目录下搜下depends.exe,这个工具可以查看.exe文件依赖的.dll,以及用到的dll中的api. 2.PE文件格式分析器: 有很多的PE格式分析器 ...

  7. 关于php网络爬虫phpspider

    前几天,被老板拉去说要我去抓取大众点评某家店的数据,当然被我义正言辞的拒绝了,理由是我不会...但我的反抗并没有什么卵用,所以还是乖乖去查资料,因为我是从事php工作的,首先找的就是php的网络爬虫源 ...

  8. JSON简介(2)

    例子: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

  9. [洛谷P1536]村村通

    题意:多组数据,当n为0时结束,每组数据表示有n个村子,m条路,求还需要建多少条路,使得所有的村子联通题解:用并查集求出有多少个联通块,然后求解 C++ Code: #include<cstdi ...

  10. HDU.2095(异或运算)

    find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...