Chemistry Experiment

维护一个权值线段树,然后二分答案。

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end() using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
vector<LL> oo;
int getPos(double x) {
return upper_bound(ALL(oo), x) - oo.begin();
}
int cnt[N << ]; LL sum[N << ];
void update(int p, int op, int l, int r, int rt) {
if(l == r) {
cnt[rt] += op;
sum[rt] += op * oo[p - ];
return;
}
int mid = (l + r) >> ;
if(p <= mid) update(p, op, lson);
else update(p, op, rson);
cnt[rt] = cnt[rt << ] + cnt[rt << | ];
sum[rt] = sum[rt << ] + sum[rt << | ];
} PLI query(int L, int R, int l, int r, int rt) {
if(L > R) return mk(, );
if(R < l || r < L) return mk(, );
if(L <= l && r <= R) return mk(sum[rt], cnt[rt]);
int mid = (l + r) >> ;
PLI tmpL = query(L, R, lson);
PLI tmpR = query(L, R, rson);
return mk(tmpL.fi + tmpR.fi, tmpL.se + tmpR.se);
} bool check(double tar, LL v) {
PLI ret = query(, getPos(tar), , SZ(oo), );
return ret.se * tar - ret.fi > v;
} int n, q;
LL qus[N][], h[N]; int main() {
scanf("%d%d", &n, &q);
for(int i = ; i <= n; i++) {
scanf("%d", &h[i]);
oo.push_back(h[i]);
}
for(int i = ; i <= q; i++) {
scanf("%d", &qus[i][]);
if(qus[i][] == ) {
scanf("%lld%lld", &qus[i][], &qus[i][]);
oo.push_back(qus[i][]);
} else {
scanf("%lld", &qus[i][]);
}
}
sort(ALL(oo));
oo.erase(unique(ALL(oo)), oo.end());
for(int i = ; i <= n; i++) update(getPos(h[i]), , , SZ(oo), );
for(int i = ; i <= q; i++) {
if(qus[i][] == ) {
int p = qus[i][], x = qus[i][];
update(getPos(h[p]), -, , SZ(oo), );
h[p] = x;
update(getPos(h[p]), , , SZ(oo), );
} else {
LL v = qus[i][];
double low = , high = 1e9 + v + ;
for(int o = ; o < ; o++) {
double mid = (low + high) / ;
if(check(mid, v)) high = mid;
else low = mid;
}
printf("%.15f\n", (low + high) / );
}
}
return ;
} /*
*/

Codeforces 431E Chemistry Experiment 线段树 + 二分的更多相关文章

  1. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  2. Codeforces Gym100543B 计算几何 凸包 线段树 二分/三分 卡常

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF-Gym100543B.html 题目传送门 - CF-Gym100543B 题意 给定一个折线图,对于每一条 ...

  3. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  4. Educational Codeforces Round 64 (Rated for Div. 2) (线段树二分)

    题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n  n个数,然后求有多少个区间[l,r] 满足    a[l]+a[r]=max([l, ...

  5. Buses and People CodeForces 160E 三维偏序+线段树

    Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...

  6. [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)

    [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...

  7. hdu4614 线段树+二分 插花

    Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...

  8. 洛谷P4344 脑洞治疗仪 [SHOI2015] 线段树+二分答案/分块

    !!!一道巨恶心的数据结构题,做完当场爆炸:) 首先,如果你用位运算的时候不小心<<打成>>了,你就可以像我一样陷入疯狂的死循环改半个小时 然后,如果你改出来之后忘记把陷入死循 ...

  9. luogu4422 [COCI2017-2018#1] Deda[线段树二分]

    讨论帖:线段树二分的题..我还考场切过..白学 这题我一年前的模拟赛考场还切过,现在就不会了..好菜啊. 显然直接线段树拆成$\log n$个区间,然后每个区间在进行线段树二分即可. UPD:复杂度分 ...

随机推荐

  1. 线程池、进程池(concurrent.futures模块)和协程

    一.线程池 1.concurrent.futures模块 介绍 concurrent.futures模块提供了高度封装的异步调用接口 ThreadPoolExecutor:线程池,提供异步调用 Pro ...

  2. jmeter笔记(3)--响应结果中文乱码的解决方式

    1.举例 新建HTTP请求访问百度首页,响应结果如下: 2.原因 Jmeter安装目录/bin/jmeter.properties中sampleresult.default.encoding默认为IS ...

  3. vue学习笔记(四)- cmd无法识别vue命令解决方法

    解决控制台无法识别vue命令问题 作者:狐狸家的鱼 本文链接:cmd无法识别vue命令解决方法 GitHub:sueRimn 在控制台输入vue会报以下错误: vue : 无法将“vue”项识别为 c ...

  4. v-charts 和 websocket实现数据展示动态推送

    v-charts https://v-charts.js.org/#/ ELEMENT力作: 在使用 echarts 生成图表时,经常需要做繁琐的数据类型转化.修改复杂的配置项,v-charts 的出 ...

  5. CSS+HTML+JQuery实现条形图

    在工作中遇到了写条形图的情况,因为文字,条形数量和条形图的颜色需要改变,所以不能用图片,所以决定写一个试试,写的比较简单,但毕竟是第一次,也遇到了一些问题,特意记录下来,以免忘记. 因为该页面还需要兼 ...

  6. win10自带邮箱添加网易企业邮箱

    开始-邮件-账户-添加账户-高级安装程序-internet电子邮件-然后输入网易企业邮箱的用户名和相关服务器设置就行了 接收服务器 pop.qiye.163.com发送服务器 smtp.qiye.16 ...

  7. RC522射频卡读写模块驱动(仅读取)

    目录 说明 测试结果 main RC522.h RC522.c 说明 更改了网上的源代码,仅保留了读取序列号并通过串口回传的功能.版本号:V1 感谢 https://blog.csdn.net/qq_ ...

  8. YYS FZU - 2278 (期望)JAVA

    题目链接: G - YYS FZU - 2278 题目大意: 我们现在想要收集到n个卡片,现在已知抽到每种卡片的概率为1/n,现在每隔(n-1)!天就可以进行一次抽奖,问收集齐所有卡片的期望天数. 具 ...

  9. 一文掌握 Linux 性能分析之 CPU 篇

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. 平常工作会涉及 ...

  10. Git入门——本地版本库操作

    作为一个一直用SVN的家伙,深深地感到了自己在版本控制工具上的落伍.... 首先必须强调的是: Git与Github不是一回事. Git是目前世界上最先进的分布式版本控制系统,于2005年被linux ...