【二分】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! Unfortunately, this year’s winter is already over, and she can’t expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
Input
The first line contains a single integer N (1 ≤ N ≤ 105) — the number of days.
The second line contains N integers V1, V2, …, VN (0 ≤ Vi ≤ 109), where Vi is the initial size of a snow pile made on the day i.
The third line contains N integers T1, T2, …, TN (0 ≤ Ti ≤ 109), where Ti is the temperature on the day i.
Output
Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
Examples
input
3
10 10 5
5 7 2
output
5 12 4
input
5
30 25 20 15 10
9 10 12 4 13
output
9 20 35 11 25
Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
http://codeforces.com/contest/948/problem/C
题意是第i天会给你一堆V[i]单位的雪,每天你的每个雪堆都会融化掉T[i]单位(包括当天的雪堆),如果一堆雪化完了就会消失,求每天融化掉的雪的量。
先处理出T[i]的前缀和ext[i],遍历每堆雪,二分V[i]+ext[i-1]在ext数组中的位置并存入day[i],即每堆雪会在哪一天消失。复杂度是o(nlog2n),顺便计算出每堆雪消失的那天融化了多少,存入remain[day[i]]中。
然后给day数组排序。
最后遍历每一天,对于第i天,可以二分day数组找到第i天之前消失的雪堆数量num, 当天融化的雪量就是(i-num)*T[i]+remain[i];
#define IN_LB() freopen("F:\\in.txt","r",stdin)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
typedef long long ll;
ll v[maxn],t[maxn],ext[maxn];
ll remain[maxn],dday[maxn];
struct node{
int ind;
int day;
}nd[maxn];
bool cmp(node a,node b){
return a.day<b.day;
}
int main() {
// IN_LB();
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++) {
scanf("%d",v+i);
}
for(int i=1; i<=n; i++) {
scanf("%d",t+i);
}
ext[1] = t[1];
for(int i=2; i<=n; i++) {
ext[i]=ext[i-1]+t[i];
}
for(int i=1; i<=n; i++) {
nd[i].ind = i;
nd[i].day = (int)(lower_bound(ext+1,ext+n+1,v[i]+ext[i-1])-ext);
remain[nd[i].day] += v[i]-ext[nd[i].day-1]+ext[i-1];
}
sort(nd+1,nd+n+1,cmp);
for(int i=1; i<=n; i++) {
dday[i] = nd[i].day;
}
for(int i=1;i<=n;i++){
int num = (int)(upper_bound(dday+1,dday+n+1,i)-dday)-1;
printf("%lld%s",(i-num)*t[i]+remain[i],i==n?"\n":" ");
}
return 0;
}
【二分】Producing Snow @Codeforces Round #470 Div.2 C的更多相关文章
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- Codeforces Round #470 Div. 2题解
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 【二分答案】Codeforces Round #402 (Div. 2) D. String Game
二分要删除几个,然后暴力判定. #include<cstdio> #include<cstring> using namespace std; int a[200010],n, ...
- Codeforces Round #470 Div. 1
A:暴力枚举x2的因子,由此暴力枚举x1,显然此时减去其最大质因子并+1即为最小x0. #include<iostream> #include<cstdio> #include ...
- Codeforces Round #470 (Div. 2) A Protect Sheep (基础)输入输出的警示、边界处理
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to w ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- 前端:Jquery 处理同一Name的Radio组时,绑定checked属性异常的问题.(已解决)
将: $("input[type=radio][name=optionsContractGroup][value=201]").attr("checked",t ...
- C# 之 @ Assembly
@ Assembly指定需要动态编译的类,在编译期间将程序集链接到 ASP.NET 应用程序页(例如网页.用户控件.母版页或 Global.asax 文件),使程序集的所有类和接口都在该页上可用. & ...
- appium---第三个脚本,进入评论页,发表评论
#进入编辑页,点击编辑框,固定光标 #com.xxx.xxx:id/edit__content drive.find_element_by_id('/edit_content').click(); t ...
- sql语句start with connect by prior语法解析
prior分两种放法: 1 放在子节点端 表示start with 指定的节点作为根节点,按照从上到下的顺序遍历 2 放在父节点端 表示start with指定的节点作为最底层节点,按照从下到上的顺序 ...
- hibernate.properties not found
在配置hibernate的主键生成策略的时候突然报出如下错误,寻找了很长时间,虽然不是什么严重的错误,但是希望可以警醒自己 问题: 11:26:21,611 INFO Version:37 - HHH ...
- NiftyNet开源平台使用
NiftyNet是一款开源的卷积神经网络平台,专门针对医学图像处理分析,上一篇博客已经详细介绍了这个平台,接下来让我简单介绍一下目前我了解到的使用方法.更详细的使用方法.以及配置过程请查看NiftyN ...
- C# 正规则表达式
获取括号里的内容 public string GetRegexStr(string Str, string Symbol1, string Symbol2, bool needSymbol) { ]; ...
- Xamarin Essentials教程设备信息DeviceInfo
Xamarin Essentials教程设备信息DeviceInfo 设备信息包括设备类型.设备种类和操作系统.应用程序通过获取设备信息,可以判断当前程序是否适合在该设备上运行.例如,优酷提供TV ...
- Numpy np.array 相关常用操作学习笔记
1.np.array构造函数 用法:np.array([1,2,3,4,5]) 1.1 numpy array 和 python list 有什么区别? 标准Python的列表(list)中,元素本质 ...
- BZOJ.4320.[ShangHai2006]Homework(根号分治 分块)
BZOJ \(\mathbb{mod}\)一个数\(y\)的最小值,可以考虑枚举剩余系,也就是枚举区间\([0,y),[y,2y),[2y,3y)...\)中的最小值(求后缀最小值也一样)更新答案,复 ...