Codeforces 923 B. Producing Snow
http://codeforces.com/contest/923/problem/B
题意:
有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti
当某一堆剩余体积vi<=Ti时,体积减少vi,雪堆消失
问每天所有雪堆一共减少多少体积
fhq treap
把<=Ti的分裂出来,计算和
>Ti 的 Ti*个数
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 100005 int a[N],t[N];
int id[N]; int tot;
int root,fa[N],ch[N][],pri[N];
int siz[N],val[N];
long long sum[N],tag[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int newnode(int v)
{
siz[++tot]=;
sum[tot]=v;
val[tot]=v;
pri[tot]=id[tot];
return tot;
} void update(int x)
{
siz[x]=siz[ch[x][]]+siz[ch[x][]]+;
sum[x]=sum[ch[x][]]+sum[ch[x][]]+val[x];
} void tagging(int x,int y)
{
val[x]-=y;
sum[x]-=1LL*siz[x]*y;
tag[x]+=y;
} void down(int x)
{
if(ch[x][]) tagging(ch[x][],tag[x]);
if(ch[x][]) tagging(ch[x][],tag[x]);
tag[x]=;
} void split(int now,int k,int &x,int &y)
{
if(!now) x=y=;
else
{
if(tag[now]) down(now);
if(val[now]<=k)
{
x=now;
split(ch[now][],k,ch[x][],y);
}
else
{
y=now;
split(ch[now][],k,x,ch[y][]);
}
update(now);
}
} int merge(int x,int y)
{
if(x && tag[x]) down(x);
if(y && tag[y]) down(y);
if(!x || !y) return x+y;
if(pri[x]<pri[y])
{
ch[x][]=merge(ch[x][],y);
update(x);
return x;
}
else
{
ch[y][]=merge(x,ch[y][]);
update(y);
return y;
}
} int main()
{
int n;
read(n);
for(int i=;i<=n;++i) read(a[i]);
for(int i=;i<=n;++i) read(t[i]);
for(int i=;i<=n+;++i) id[i]=i;
random_shuffle(id+,id+n+);
int x,y,z;
for(int i=;i<=n;++i)
{
//insert(a[i]);
split(root,a[i],x,y);
root=merge(merge(x,newnode(a[i])),y);
split(root,t[i],x,y);
cout<<sum[x]+1LL*t[i]*siz[y]<<' ';
if(y) tagging(y,t[i]);
root=y;
}
return ;
}
Codeforces 923 B. Producing Snow的更多相关文章
- Codeforces I. Producing Snow(优先队列)
题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 【二分】Producing Snow @Codeforces Round #470 Div.2 C
time limit per test: 1 second memory limit per test: 256 megabytes Alice likes snow a lot! Unfortuna ...
- Codeforces 948C Producing Snow(优先队列+思维)
题目链接:http://codeforces.com/contest/948/problem/C 题目大意:给定长度n(n<=1e5),第一行v[i]表示表示第i堆雪的体积,第二行t[i]表示第 ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- 2018.12.05 codeforces 948C. Producing Snow(堆)
传送门 维护一个堆. 每次先算出一个都不弹掉的总贡献. 然后把要弹掉的弹掉,并减去它们对应的贡献. 代码: #include<bits/stdc++.h> #define ri regis ...
- CodeForces - 948C Producing Snow(优先队列)
题意: n天. 每天你会堆一堆雪,体积为 v[i].每天都有一个温度 t[i] 所有之前堆过的雪在第 i 天体积都会减少 t[i] . 输出每天融化了的雪的体积. 这个题的正解我怎么想都很难理解,但是 ...
- Codeforces 923 D. Picking Strings
http://codeforces.com/contest/923/problem/D 题意: A-->BC , B-->AC , C-->AB , AAA-->empty 问 ...
- Codeforces 923 C. Perfect Security
http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...
- Codeforces 923 A. Primal Sport
http://codeforces.com/contest/923/problem/A 题意: 初始有一个x0,可以选择任意一个<x0的质数p,之后得到x1为≥x0最小的p的倍数 然后再通过x1 ...
随机推荐
- 2017qq红包雨最强攻略
这个只支持苹果手机,而且要有苹果电脑,只有苹果手机是不行的. QQ红包规则:只要你到达指定的位置,就可以领取附近的红包,一般也就几毛,还有几分的,当然也不排除有更高的,只不过我是没遇到... 那么既然 ...
- OD之破解密钥文件授权(三)
除了上次的序列号验证以外,还有这种密钥授权模式,需要密钥文件授权才能打开文件; 老办法,先拖进OD中动态分析再说: 然后F8进行调试这时候发现了一个条件跳转函数jnz下面是说跳转未实现,那我们发现上面 ...
- OpenGL学习(2)——绘制三角形
在创建窗口的基础上,添加代码实现三角形的绘制. 声明和定义变量 在屏幕上绘制一个三角形需要的变量有: 三角形的三个顶点坐标: Vertex Buffer Object 将顶点数据存储在GPU的内存中: ...
- 阿里(蚂蚁,菜鸟)+百度+网易面经(JAVA)
本人综述: 本人本科和硕士均是毕业于普通的双非院校,参加过ACM竞赛,阿里面了三次全被拒了,网易收到offer. 阿里面试: 阿里的面试问的都是很基础的东西,如操作系统的简单问题,计算机网络的基本问题 ...
- PAT甲题题解-1037. Magic Coupon (25)-贪心,水
题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include ...
- PAT甲级题解-1047. Student List for Course (25)-排序
一开始是建立了course[2501][40001]数组,存储每节课的学生编号然后for循环两层输出,但这样复杂度为O(2500*40000),也很明显导致最后时间超时后来发现最多40000学生,每个 ...
- CSAPP lab2 二进制拆弹 binary bombs phase_4
给出对应于7个阶段的7篇博客 phase_1 https://www.cnblogs.com/wkfvawl/p/10632044.htmlphase_2 https://www.cnblogs. ...
- Top 10 Javascript MVC 框架
在网上偶然看到了,几种MVC框架各有优缺点,但Backbone和Ember的呼声相对更高-大家参考一下哈- http://codebrief.com/2012/01/the-top-10-javasc ...
- 睡眠猴子——beta阶段项目总结
Questions: 每个成员在beta 阶段的实践和alpha 阶段有何改进? 团队在beta 阶段吸取了那些alpha 阶段的经验教训? 12 条敏捷开发的原则中, 团队做得最好和最不好的各列 ...
- Hadoop 5 Hbase 遇到的问题
hbase伪分布式配置完成后: 在bin/hbase shell 进行create操作时出现:Can't get master address from ZooKeeper; znode data = ...