题目大意

题解

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

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

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



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

代码

  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cstdio>
  4. int read() {
  5. int x = 0, f = 1;
  6. char ch = getchar();
  7. while (!isdigit(ch)) {
  8. if (ch == '-')
  9. f = -1;
  10. ch = getchar();
  11. }
  12. while (isdigit(ch)) {
  13. x = x * 10 + ch - '0';
  14. ch = getchar();
  15. }
  16. return x * f;
  17. }
  18. int N, M;
  19. struct line {
  20. double k, b;
  21. int id;
  22. double getf(int x) { return k * x + b; };
  23. };
  24. bool cmp(line a, line b, int x) {
  25. if (!a.id)
  26. return 1;
  27. return a.getf(x) != b.getf(x) ? a.getf(x) < b.getf(x) : a.id < b.id;
  28. }
  29. const int maxn = 50010;
  30. line t[maxn << 2];
  31. line query(int k, int l, int r, int x) {
  32. if (l == r)
  33. return t[k];
  34. int mid = (l + r) >> 1;
  35. line tmp;
  36. if (x <= mid)
  37. tmp = query(k << 1, l, mid, x);
  38. else
  39. tmp = query(k << 1 | 1, mid + 1, r, x);
  40. return cmp(t[k], tmp, x) ? tmp : t[k];
  41. }
  42. void insert(int k, int l, int r, line x) {
  43. if (!t[k].id)
  44. t[k] = x;
  45. if (cmp(t[k], x, l))
  46. std::swap(t[k], x);
  47. if (l == r || t[k].k == x.k)
  48. return;
  49. int mid = (l + r) >> 1;
  50. double X = (t[k].b - x.b) / (x.k - t[k].k);
  51. if (X < l || X > r)
  52. return;
  53. if (X <= mid)
  54. insert(k << 1, l, mid, t[k]), t[k] = x;
  55. else
  56. insert(k << 1 | 1, mid + 1, r, x);
  57. }
  58. void Insert(int k, int l, int r, int x, int y, line v) {
  59. if (x <= l && r <= y) {
  60. insert(k, l, r, v);
  61. return;
  62. }
  63. int mid = (l + r) >> 1;
  64. if (x <= mid)
  65. Insert(k << 1, l, mid, x, y, v);
  66. if (y > mid)
  67. Insert(k << 1 | 1, mid + 1, r, x, y, v);
  68. }
  69. int main() {
  70. #ifdef D
  71. freopen("input", "r", stdin);
  72. #endif
  73. M = read();
  74. N = 50000;
  75. char opt[15];
  76. while (M--) {
  77. scanf("%s", opt);
  78. if (opt[0] == 'P') {
  79. double k, b;
  80. scanf("%lf %lf", &k, &b);
  81. line tmp;
  82. tmp.k = b;
  83. tmp.b = k - b;
  84. tmp.id = 1;
  85. Insert(1, 1, N, 1, N, tmp);
  86. }
  87. int x;
  88. if (opt[0] == 'Q') {
  89. x = read();
  90. printf("%lld\n", (long long)(query(1, 1, N, x).getf(x) / 100 + 1e-8));
  91. }
  92. }
  93. return 0;
  94. }

[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. 一个极为简单的requirejs实现

    require和 sea的源码分析,我之前的博客有写过, 今天我想分享的是一个很简单的核心代码(不带注释和空行大概60行), 没有容错判断. require.js require函数实现用一句话概括: ...

  2. 从底层带你理解Python中的一些内部机制

    下面博文将带你创建一个字节码级别的追踪API以追踪Python的一些内部机制,比如类似YIELDVALUE.YIELDFROM操作码的实现,推式构造列表(List Comprehensions).生成 ...

  3. 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 ...

  4. tcp四次撒手

    转自:http://www.cnblogs.com/cy568searchx/p/3711670.html 由于TCP连接是全双工的,因此每个方向都必须单独进行关闭.这个原则是当一方完成它的数据发送任 ...

  5. 关于debian配置的问题汇总

    debian的apache多域名配置: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-ho ...

  6. Football Games(思维题)

    Problem Description A mysterious country will hold a football world championships---Abnormal Cup, at ...

  7. 详细解析@Resource和@Autowired的区别 , 以及@Qualifier的作用

    (41)  (0) 首先 . @Resource是javax.annotation 包中的注解类 , 是jdk中封装的 . @AutoWired是spring的中注解,依赖于spring上下文. 相同 ...

  8. elasticsearch this is not a http port

    访问的是elastic search的tcp端口,需换成http端口. elastic search默认tcp端口9300,http端口9200 如果浏览器中访问http://localhost:92 ...

  9. [CCF] 201612-2 工资计算

    [思路]按照题意对初始工资S进行循环,计算缴税后工资,若与T相等则退出循环,输出结果. #include <iostream> #include <windows.h> usi ...

  10. Hibernate关联映射之_一对多

    domain: package org.zln.hibernate.domain; import java.util.Set; /** * 部门Domain对象 * Created by sherry ...