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 ...
随机推荐
- 矩阵分解----Cholesky分解
矩阵分解是将矩阵拆解成多个矩阵的乘积,常见的分解方法有 三角分解法.QR分解法.奇异值分解法.三角分解法是将原方阵分解成一个上三角矩阵和一个下三角矩阵,这种分解方法叫做LU分解法.进一步,如果待分解的 ...
- jupyter notebook 更改工作环境和浏览器
转载自:https://blog.csdn.net/u011141114/article/details/78556227 1 修改默认目录 最近刚刚开始学习Python,比较好的一个IDE就是jup ...
- vector读入指定行数但不指定列数的数字
#include <iostream> #include <vector> #include <cstdio> #include <cstring> # ...
- PHP Laravel 连接并访问数据库
第一次连接数据库 数据库配置位于config/database.php数据库用户名及密码等敏感信息位于.env文件创建一个测试表laravel_course <?php namespace Ap ...
- Daily Scrum NO.3
工作概况 符美潇(PM) 昨日完成的工作 1.Daily Scrum.日常会议及日常工作的分配和查收. 2.整合各DEV所写的代码,在TFS上进行Beta阶段第一次代码签入. 今日工作 1.Daily ...
- java常见编码
摘自:http://www.cnblogs.com/yaya-yaya/p/5768616.html 红色 主要点 灰色 内容 绿色 知识点 橘色 补充内容 几种常见的编码格式 ...
- [2017BUAA软工]结对项目-数独程序扩展
零.github地址 GitHub地址:https://github.com/Liu-SD/SudoCmd (这个地址是命令行模式数独的仓库,包含了用作测试的BIN.DLL核心计算模块地址是:http ...
- ibmv7000查看序列号
ssh后 命令:lsenclosure 有以下数据 id status type managed IO_group_id IO_group_name product_MTM serial ...
- [Delphi]实现使用TIdHttp控件向https地址Post请求[转]
开篇:公司之前一直使用http协议进行交互(比如登录等功能),但是经常被爆安全性不高,所以准备改用https协议.百度了一下资料,其实使用IdHttp控件实现https交互的帖子并不少,鉴于这次成功实 ...
- Docker(七)-Dcoker常用命令
容器生命周期管理 run start/stop/restart kill rm pause/unpause create exec 容器操作 ps inspect top attach events ...