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. centos7修改网卡名称为eth0

    原文链接:https://www.cnblogs.com/freeblogs/p/7881597.html 在安装系统的时候配置: 修改内核选项:net.ifnames=0 biosdevname=0 ...

  2. grafana-Admin密码重置

    1)查看Grafana配置文件,确定grafana.db的路径 [paths] ;data = /var/lib/grafana [database] # For "sqlite3" ...

  3. CMDB服务器管理系统【s5day91】:数据库表结构补充

    1.表机构补充图 2.用户信息表(UserProfile) 1.解决了什么问题 1.这台服务器是谁管理的?2.真正出问题了我敢上去改代码了?不能3.所以一台机器必须有运维人员和业务负责人,但是业务负责 ...

  4. Entity Framework入门教程(6)--- 在线场景中保存数据

    在线场景中保存数据 在线场景中保存实体数据是一项相当容易的任务,因为使用的是同一个context,这个context会自动跟踪所有实体发生的更改. 下图说明了在线场景中的CUD(创建,更新,删除)操作 ...

  5. .net异步委托

    委托Delegate是一个类,定义了方法的类型, 使得可以将方法当做另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大佬使用If-Else(Switch)语句,同时使得程序 ...

  6. SpringBoot系列: RestTemplate 快速入门

    ====================================相关的文章====================================SpringBoot系列: 与Spring R ...

  7. 本地图片上传与H5适配知识

    最近用到本地图片上传作为API的参数,在网上看了许多,记录一下,以后可能用的着(仅自己记录用,看不清请绕路) function getObjectURL(file) { var url = null ...

  8. 【听大佬rqy分享有感】

    rqy,一个神奇的名字,一个神奇的物种. 初三自学高等数学,无师自通:获得了大大小小的oi奖项:是也一直是山东省信息学的“红太阳”:今天听了他的分享,真的很有帮助. 1.  不必太较真:遇到不会的高数 ...

  9. 20165230 Exp3 免杀原理与实践

    目录 1.实验内容 2.基础问题回答 3.实验内容 任务一:正确使用免杀工具或技巧 使用msf编码器,msfvenom生成如jar之类的其他文件 使用veil-evasion 自己利用shellcod ...

  10. Linux 一 些常用的命令

    查看当前系统JAVA的安装路径: echo $JAVA_HOME: 查看内核版本: uname -a ubuntu的防火墙 关闭:ufw disable开启:ufw enable 卸载了 iptabl ...