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 ...
随机推荐
- 5、Docker网络配置(单机)
一.概述 以下内容参考:https://docs.docker.com/network/#network-drivers Docker容器和服务如此强大的原因之一是您可以将它们连接在一起,或者将它们连 ...
- React半科普文
React半科普文 什么是React getting started 文件分离 Server端编译 定义一个组件 使用property 组件嵌套 组件更新 Virtual DOM react nati ...
- web安全入门课程笔记——网站基础与信息搜集
2-1 网站的基本概念 URL统一资源定位符 这是一个动态页面 ?ID 查询条件 后台数据库最有可能:ACCESS Web容器(web容器是一种服务程序,在服务器一个端口就有一个提供相应服务的程序,而 ...
- 从两个设计模式到前端MVC-洪宇
引言 本文将从策略模式和观察者模式两个设计模式讲起,接着过渡到一个经典的复合模式- MVC架构,进而介绍MVC在Web上的适应-Model2架构.之后,我们将视野扩展到前端MVC,看一看前端MVC经典 ...
- linux内核分析第一次实验
http://blog.sina.com.cn/s/blog_78e559950102wneg.html
- java入门--4111:判断游戏胜者-Who Is the Winner
基础的题目 学习了StringBuilder, 通过delete来清空它 学了Map的简单用法 import java.util.*; public class Main { public stati ...
- 每日Scrum(8)
今天:在程序中嵌入剖面图,进行美化 明天:测试分析,找学弟学妹来体验我们的软件 任务看板: 燃尽图:
- Beta阶段冲刺-3
一. 每日会议 1. 照片 2. 昨日完成工作 3. 今日完成工作 4. 工作中遇到的困难 杨晨露:组内图表部分遇到了问题,他们的问题一出来,我就头疼了......因为要调整计划时间,所以我觉得我的困 ...
- Java Socket 多线程聊天室
本来这次作业我是想搞个图形界面的,然而现实情况是我把题意理解错了,于是乎失去了最初的兴致,还是把程序变成了功能正确但是“UI”不友好的console了,但是不管怎么样,前期的图形界面的开发还是很有收获 ...
- 把Excel转换成DataTable,Excel2003+
在数据处理的时候,我们会Excel(包含2003.2007.2010等)转换成DataTable,以便进一步操作 1.怎么访问Excel文件呢?我们可以通过OLEDB接口访问,如下: private ...