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 ...
随机推荐
- Egret(白鹭引擎)——“TypeError: Cannot read property 'asCom' of null”
前言 相信我,这个错误新手都不陌生:TypeError: Cannot read property 'asCom' of null 还有,一定要看我上一篇,哦不(人家应该是报了这个错,才找到看到这篇文 ...
- winform 记事本 剪切 粘贴 全选 撤销
private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e) { textBox1.Undo(); } private voi ...
- JavaScript 为什么不要使用 eval
本文内容 eval 隐藏的 eval 安全问题 结论 参考资料 eval eval 函数是一个高等级的函数,它与任何对象都无关.其参数,如果是一个字符串表达式,那么该函数计算表达式的值:如果是一个 ...
- Mistakes I Made(as a developer)...大龄程序员的忠告...(部分转...)
在2006年,我开始了编程工作.当意识到来到了十年这个重要的时间关口时,我觉得有必要回顾一下这十年间所犯下的错误,做一做经验总结,并且给正在这个职业上奋斗的人们提出我的一些忠告.开发行业变化得很快,我 ...
- 上云利器,K8S应用编排设计器之快到极致
前言在前面的文章中,我们已经提到,华为云有一个上云利器:应用编排设计器.作为华为云应用编排服务与用户沟通的桥梁,设计器坚持用户体验至上的理念,以图形化方式,在鼠标点击之间,助力企业快速上云.优质的交互 ...
- 实验吧CTF天网管理系统
天网你敢来挑战嘛 格式:ctf{ } 解题链接: http://ctf5.shiyanbar.com/10/web1/ 打开链接后,嗯,光明正大的放出账号密码,肯定是登不进的,查看源代码 看来是和md ...
- PAT甲题题解-1022. Digital Library (30)-map映射+vector
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789235.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- uc浏览器app点评
uc浏览器app我经常用,是我接触的第一款手机浏览器,感觉还不错的,uc浏览器新闻更新速度有点慢,有时候还闪退,以前在搜索栏粘贴文字后,如果想改后面的文字,根本就不行,用uc浏览器下东西速度比较慢,现 ...
- windows8/10+Ubuntu Kylin(优麒麟)双系统
1.参考资料:http://www.jianshu.com/p/2eebd6ad284d 中第三种U盘启动方式安装完成 2.安装过程: (1)首先将一个盘空出来,做好其中数据的备份.启动win+X磁盘 ...
- 第二个Sprint
能够实现三个数,两个操作符的四则运算.