题目链接

传送门

题意

有\(n\)棵竹子,然后有\(q\)次操作,每次操作给你\(l,r,x,y\),表示对\([l,r]\)区间的竹子砍\(y\)次,每次砍伐的长度和相等(自己定砍伐的高度\(len\),该区间大于\(len\)的树木都要砍到\(len\)),问你第\(x\)次砍的高度是多少(注意在经过\(y\)次砍伐后该区间的竹子的高度都会变成\(0\),询问之间互不影响)。

思路

由于在\(y\)次砍伐后树木高度都变为\(0\),且每次砍伐的总长度都相等,因此每次砍伐的长度和为该区间内竹子高度之和除以\(y\),前\(x\)砍伐的总高度为\(x*len\),然后二分第\(x\)次砍伐的高度,在主席树里面找大于砍伐高度的竹子有多少棵(记为\(sum1\)),这些竹子的高度和为\(sum2\),然后比较\(sum2-sum1*mid\)与\(x*len\)的关系调整上下界。

因为生日回家了几天,咕了两场多校,写几篇水题博客假装自己有在训练~

代码

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson (rt<<1),L,mid
#define rson (rt<<1|1),mid + 1,R
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 200000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int n, q, cnt, l, r, x, y;
int root[maxn];
LL sum1, sum2, sum[maxn]; struct node {
int l, r;
LL sum1, sum2;
}tree[maxn*40]; void update(int l, int r, int& x, int y, int pos) {
tree[++cnt] = tree[y], tree[cnt].sum1 += 1, tree[cnt].sum2 += pos, x = cnt;
if(l == r) return;
int mid = (l + r) >> 1;
if(pos <= mid) update(l, mid, tree[x].l, tree[y].l, pos);
else update(mid + 1, r, tree[x].r, tree[x].r, pos);
} void query(int l, int r, int x, int y, double pos) {
if(l == r) {
if(pos - l >= eps) {
sum1 += tree[y].sum1 - tree[x].sum1;
sum2 += tree[y].sum2 - tree[x].sum2;
}
return;
}
int mid = (l + r) >> 1;
if(mid - pos > eps) query(l, mid, tree[x].l, tree[y].l, pos);
else {
sum1 += tree[tree[y].l].sum1 - tree[tree[x].l].sum1;
sum2 += tree[tree[y].l].sum2 - tree[tree[x].l].sum2;
query(mid + 1, r, tree[x].r, tree[y].r, pos);
}
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%d", &x);
sum[i] = sum[i-1] + x;
update(0, 100000, root[i], root[i-1], x);
}
while(q--) {
scanf("%d%d%d%d", &l, &r, &x, &y);
double len = 1.0 * (sum[r] - sum[l-1]) / y * x;
double ub = 100000.0, lb = 0.0, mid, ans = 0.0;
for(int i = 0; i < 100; ++i) {
mid = (ub + lb) / 2;
sum1 = sum2 = 0;
query(0, 100000, root[l-1], root[r], mid);
double tot = 1.0 * (sum[r] - sum[l-1] - sum2);
double big = 1.0 * (r - l + 1 - sum1);
if(tot - big * mid - len > eps) {
ans = mid;
lb = mid;
} else {
ub = mid;
}
}
printf("%.7f\n", ans);
}
return 0;
}

Cutting Bamboos(2019年牛客多校第九场H题+二分+主席树)的更多相关文章

  1. 2019年牛客多校第一场 H题XOR 线性基

    题目链接 传送门 题意 求\(n\)个数中子集内所有数异或为\(0\)的子集大小之和. 思路 对于子集大小我们不好维护,因此我们可以转换思路变成求每个数的贡献. 首先我们将所有数的线性基的基底\(b\ ...

  2. 2019年牛客多校第二场 H题Second Large Rectangle

    题目链接 传送门 题意 求在\(n\times m\)的\(01\)子矩阵中找出面积第二大的内部全是\(1\)的子矩阵的面积大小. 思路 处理出每个位置往左连续有多少个\(1\),然后对每一列跑单调栈 ...

  3. 2019年牛客多校第一场B题Integration 数学

    2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...

  4. 牛客多校第九场H Cutting Bamboos(主席树 区间比k小的个数)题解

    题意: 标记为\(1-n\)的竹子,\(q\)个询问,每次给出\(l,r,x,y\).要求为砍区间\(l,r\)的柱子,要求砍\(y\)次把所有竹子砍完,每次砍的时候选一个高度,把比他高的都砍下来,并 ...

  5. 2019年牛客多校第一场 I题Points Division 线段树+DP

    题目链接 传送门 题意 给你\(n\)个点,每个点的坐标为\((x_i,y_i)\),有两个权值\(a_i,b_i\). 现在要你将它分成\(\mathbb{A},\mathbb{B}\)两部分,使得 ...

  6. 2019年牛客多校第一场 B题 Integration 数学

    题目链接 传送门 思路 首先我们对\(\int_{0}^{\infty}\frac{1}{\prod\limits_{i=1}^{n}(a_i^2+x^2)}dx\)进行裂项相消: \[ \begin ...

  7. MAZE(2019年牛客多校第二场E题+线段树+矩阵乘法)

    题目链接 传送门 题意 在一张\(n\times m\)的矩阵里面,你每次可以往左右和下三个方向移动(不能回到上一次所在的格子),\(1\)表示这个位置是墙,\(0\)为空地. 现在有\(q\)次操作 ...

  8. Kth Minimum Clique(2019年牛客多校第二场D题+k小团+bitset)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 找第\(k\)小团. 思路 用\(bitset\)来标记每个结点与哪些结点直接有边,然后进行\(bfs\),在判断新加入的点与现在有的点是否都 ...

  9. 2019年牛客多校第二场 F题Partition problem 爆搜

    题目链接 传送门 题意 总共有\(2n\)个人,任意两个人之间会有一个竞争值\(w_{ij}\),现在要你将其平分成两堆,使得\(\sum\limits_{i=1,i\in\mathbb{A}}^{n ...

随机推荐

  1. [LeetCode] 95. Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ...

  2. shell脚本特殊变量($0、$1、$2、 $?、 $# 、$@、 $*)

    $0        Shell本身的文件名$1-$n 添加到Shell的各参数值.$1是第1参数.$2是第2参数…$$        Shell本身的PID(ProcessID) $!         ...

  3. makfile通用版本

    DIR_INC = ./include DIR_SRC = ./src DIR_OBJ = ./obj DIR_BIN = ./bin LIBS += -Wl,-rpath=../lib/HCNetS ...

  4. 比较两个jar包的版本号

    一.背景 我们经常会遇到比较两个jar包的版本号,这里贴下相关实现. 请尊重作者劳动成果,转载请标明原文链接:https://www.cnblogs.com/waterystone/p/1138547 ...

  5. Windows搭建FTP/Http文件共享(利用IIS)

    控制面板——程序——添加功能 勾选Ftp服务器.万维网服务.IIS管理控制台 然后,计算机——右键管理——服务和应用程序,添加网站和添加Ftp IP设置为 未分配 或 本机获取到的静态IP即可. 然后 ...

  6. 《30天自制操作系统》笔记3 --- (Day2 上节)完全解析文件系统

    Day2 汇编语言学习与Makefile入门 本文仅带着思路,研究源码里关于文件系统的参数 关于day2主程序部分及更多内容,请看<30天自制操作系统>笔记 导航 发现学习中的变化 源码差 ...

  7. 后端设置Cookie前端跨域获取丢失问题(基于springboot实现)

    1.跨域问题说明:后端域名为A.abc.com,前端域名为B.abc.com. 2.后端设置一个cookie发送给前台,domain应该是setDomain(“abc.com”),而不是setDoma ...

  8. i2c的读写时序图

    根据实际示波器的波形画的时序图,时序图不好画,小小一幅图,画了两个小时,分享之:

  9. 安装Office 2016 出现 Office 16 Click-to-Run Extensibility Component

    无法安装 64 位版本的 Office,因为在您的 PC 上找到了以下 32 位程序: Office 16 Click-to-Run Extensibility Component 请卸载所有 32 ...

  10. scala中nothing和null的区别

    1:nothing是所有类型的子类,他没有具体的实例对象,常见的应用:抛出异常.程序exit.无线循环等. 2:nothing是所有类型的子类,也是null的子类,nothing没有对象,但是可以用来 ...