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的更多相关文章

  1. Codeforces I. Producing Snow(优先队列)

    题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. 【二分】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 ...

  3. Codeforces 948C Producing Snow(优先队列+思维)

    题目链接:http://codeforces.com/contest/948/problem/C 题目大意:给定长度n(n<=1e5),第一行v[i]表示表示第i堆雪的体积,第二行t[i]表示第 ...

  4. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  5. 2018.12.05 codeforces 948C. Producing Snow(堆)

    传送门 维护一个堆. 每次先算出一个都不弹掉的总贡献. 然后把要弹掉的弹掉,并减去它们对应的贡献. 代码: #include<bits/stdc++.h> #define ri regis ...

  6. CodeForces - 948C Producing Snow(优先队列)

    题意: n天. 每天你会堆一堆雪,体积为 v[i].每天都有一个温度 t[i] 所有之前堆过的雪在第 i 天体积都会减少 t[i] . 输出每天融化了的雪的体积. 这个题的正解我怎么想都很难理解,但是 ...

  7. Codeforces 923 D. Picking Strings

    http://codeforces.com/contest/923/problem/D 题意: A-->BC , B-->AC , C-->AB , AAA-->empty 问 ...

  8. Codeforces 923 C. Perfect Security

    http://codeforces.com/contest/923/problem/C Trie树 #include<cstdio> #include<iostream> us ...

  9. Codeforces 923 A. Primal Sport

    http://codeforces.com/contest/923/problem/A 题意: 初始有一个x0,可以选择任意一个<x0的质数p,之后得到x1为≥x0最小的p的倍数 然后再通过x1 ...

随机推荐

  1. Yeoman的好基友:Grunt

    grunt介绍 前端不能承受之痛 1.这是我们的生活 文件压缩:YUI Compressor.Google Closure 文件合并:fiddler + qzmin 文件校验:jshint 雪碧图:c ...

  2. RabbitMq基础教程之基本概念

    RabbitMq基础教程之基本概念 RabbitMQ是一个消息队列,和Kafka以及阿里的ActiveMQ从属性来讲,干的都是一回事.消息队列的主要目的实现消息的生产者和消费者之间的解耦,支持多应用之 ...

  3. 【zigbee 】2.4G信号发放器 AT2401C PA功放

    概述 AT2401C 是一款面向Zigbee,无线传感网络以及其他2.4GHz 频 段无线系统的全集成射频功能的射频前端单芯片.AT2401C 是采用 CMOS 工艺实现的单芯片器件,其内部集成了功率 ...

  4. 使用SSH过程中遇到的几个问题及解决方案

    一.HTTP Status 500 - org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: B ...

  5. wc 统计程序

    WC项目要求 这个项目要求写一个命令行程序,模仿已有的wc.exe的功能,并加以扩充,给出某程序设计源语言文件的字符数.单词数和行数.给实现一个统计程序,它能正确统计程序文件的字符数.单词数.行数,以 ...

  6. IIS错误提示:另一个程序正在使用此文件 进程无法访问

    在IIS管理中,启动一个配置好的网站时,提示:另一个程序正在使用此文件 进程无法访问 原因:网站绑定端口被占用 解决办法:更换绑定端口或者将占用此端口的程序关掉即可

  7. ElasticSearch 2 (24) - 语言处理系列之停用词:性能与精度

    ElasticSearch 2 (24) - 语言处理系列之停用词:性能与精度 摘要 在信息检索早期,磁盘和内存相较我们今天的使用只是很小的一部分.将索引空间保持在一个较小的水平是至关重要的,节省每个 ...

  8. ElasticSearch 2 (23) - 语言处理系列之词根提取

    ElasticSearch 2 (23) - 语言处理系列之词根提取 摘要 世界上大多数语言都是屈折变化的,意思是词语可以通过变形来表达不同的含义: 数(Number): fox, foxes 时态( ...

  9. 蜗牛慢慢爬 LeetCode 22. Generate Parentheses [Difficulty: Medium]

    题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...

  10. image 样式设置

    .image-fluid:响应式大小 .image-thumbnails:照片四周会出现一个1px宽的边框 .figure:用于<figure>标签,用来标记一个图像 .figure-ca ...