codeforces 626 G. Raffles(线段树+思维+贪心)
题目链接:http://codeforces.com/contest/626/problem/G
题解:这题很明显买彩票肯定要买贡献最大的也就是说买p[i]*(num[i]+1)/(num[i]+a[i]+1)-p[i]*num[i]/(num[i]+a[i])的最大值,当然这个最大值时随时改变的所以要用线段树来维护,先不考虑加彩票减彩票,可以先一开始for一遍全部的彩票先买好,然后再加彩票的或者减彩票的时候考虑不买那个改买那个。这个就需要在线段树上维护一个买一张获得贡献最大的点和不买那个减掉的贡献最小的一个,每次修改只要更新这个线段树上的这两个点就行。最后注意一下细节
#include <iostream>
#include <cstring>
#include <cstdio>
#define inf 100000000000000
using namespace std;
typedef double db;
typedef long long ll;
const db lim = 1e-;
const int M = 2e5 + ;
int a[M] , num[M];
db p[M];
struct TnT {
int l , r;
int fi , se;
db win , lose , ans;
}T[M << ];
void push_up(int i) {
T[i].ans = T[i << ].ans + T[(i << ) | ].ans;
T[i].win = max(T[i << ].win , T[(i << ) | ].win);
T[i].lose = min(T[i << ].lose , T[(i << ) | ].lose);
if(T[i].win == T[i << ].win) T[i].fi = T[i << ].fi;
else T[i].fi = T[(i << ) | ].fi;
if(T[i].lose == T[i << ].lose) T[i].se = T[i << ].se;
else T[i].se = T[(i << ) | ].se;
}
void getnum(int i , int l) {
T[i].ans = p[l] * (1.0 * num[l]) / (1.0 * (num[l] + a[l]));
T[i].ans = min(T[i].ans , 1.0 * p[l] / (1.0 * ));
if(num[l] >= a[l]) T[i].win = 0.0;
else T[i].win = p[l] * (1.0 * (num[l] + )) / (1.0 * (num[l] + a[l] + )) - p[l] * (1.0 * num[l]) / (1.0 * (num[l] + a[l]));
if(num[l] == ) T[i].lose = 1.0 * inf;
else if(num[l] > a[l]) T[i].lose = 0.0;
else T[i].lose = p[l] * (1.0 * num[l]) / (1.0 * (num[l] + a[l])) - p[l] * (1.0 * (num[l] - )) / (1.0 * (num[l] + a[l] - ));
T[i].fi = l , T[i].se = l;
}
void build(int l , int r , int i) {
int mid = (l + r) >> ;
T[i].l = l , T[i].r = r , T[i].win = , T[i].lose = , T[i].ans = ;
if(l == r) {
getnum(i , l);
return ;
}
build(l , mid , i << );
build(mid + , r , (i << ) | );
push_up(i);
}
void update(int pos , int i) {
int mid = (T[i].l + T[i].r) >> ;
if(pos == T[i].l && T[i].r == pos) {
getnum(i , pos);
return ;
}
if(mid < pos) update(pos , (i << ) | );
else update(pos , i << );
push_up(i);
}
int main() {
int n , t , q;
memset(num , , sizeof(num));
scanf("%d%d%d" , &n , &t , &q);
for(int i = ; i <= n ; i++) {
scanf("%lf" , &p[i]);
}
for(int i = ; i <= n ; i++) {
scanf("%d" , &a[i]);
}
build( , n , );
for(int i = ; i <= t ; i++) {
int now = T[].fi;
num[now]++;
update(now , );
}
while(q--) {
int t , r;
scanf("%d%d" , &t , &r);
if(t == ) a[r]++;
else a[r]--;
update(r , );
while(T[].win - T[].lose > lim) {
int now1 = T[].fi , now2 = T[].se;
num[now1]++ , num[now2]--;
update(now1 , );
update(now2 , );
}
printf("%.8lf\n" , T[].ans);
}
return ;
}
codeforces 626 G. Raffles(线段树+思维+贪心)的更多相关文章
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- CodeForces 877E DFS序+线段树
CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...
- 【arc073e】Ball Coloring(线段树,贪心)
[arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...
- 【agc028E】High Elements(动态规划,线段树,贪心)
[agc028E]High Elements(动态规划,线段树,贪心) 题面 AtCoder 你有一个\([1,N]\)的排列\(P\). 一个长度为\(N\)的字符串\(S\)是好的,当且仅当: 两 ...
- Buses and People CodeForces 160E 三维偏序+线段树
Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...
- [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)
[Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...
- [Codeforces 1199D]Welfare State(线段树)
[Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...
- [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)
[Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...
随机推荐
- 【iOS】tableView:cellForRowAtIndexPath: 方法未调用
今天遇到这个问题, UITableView 的代理方法 tableView:cellForRowAtIndexPath: - (UITableViewCell *)tableView:(UITable ...
- Web容器启动中执行某个Java类
1.监听(Listener) <!-- 配置监听 --> <listener> <listener-class>com.xian.jdbc.GetPropertie ...
- 使用 OpenSSL为WindowsServer远程桌面(RDP)创建自签名证书 (Self-signed SSL certificate)
前言 笔者查阅很多资料,才写成此文章,如有错误,请读者们及时提出. 一般大家使用远程桌面(Remote Desktop)连接Windows Server时,总会有一个警告提示,如图1 图1 出现此警告 ...
- JAVA基础知识(二):List接口、ArrayList类和LinkedList类
List接口继承了Collection接口,位于java.util包中.它包含Collection接口的所有方法,外加其他一些方法(具体实现参考源码),比较重要的有: anyType get(int ...
- 精准测试与开源工具Jacoco的覆盖率能力大PK
导读:本文根据实际使用情况,简要分析了精准测试和类Jacoco等传统白盒工具在设计理念.功能和应用场景的异同点,并阐述了覆盖率技术如何在新型企业开发体系中,发挥应有的重要作用. 覆盖率技术可以说是测试 ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- 免费IP代理池定时维护,封装通用爬虫工具类每次随机更新IP代理池跟UserAgent池,并制作简易流量爬虫
前言 我们之前的爬虫都是模拟成浏览器后直接爬取,并没有动态设置IP代理以及UserAgent标识,本文记录免费IP代理池定时维护,封装通用爬虫工具类每次随机更新IP代理池跟UserAgent池,并制作 ...
- ElasticSearch 安装与使用
目录 Elastic Search Docker中安装ElasticSearch Elastic Search API得使用 创建Index: 修改Index Mapping: 修改Index Set ...
- Spring入门(九):运行时值注入
Spring提供了2种方式在运行时注入值: 属性占位符(Property placeholder) Spring表达式语言(SpEL) 1. 属性占位符 1.1 注入外部的值 1.1.1 使用Envi ...
- vue 使用gojs绘制简单的流程图
在vue项目中需要展示工作流进度,可以使用的流程图插件很多 flowchart.js http://adrai.github.io/flowchart.js/ , 基于SVG创建Flow Chart ...