【二分】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后和给 ...
随机推荐
- 执行shell脚本提示“-bash: ./checkP.sh: /bin/sh^M: bad interpreter: No such file or directory”解决方法
在windows机器下新建了一个shell脚本如下
- 使用spark集成kudu做DDL
spark对kudu表的创建 定义kudu的表需要分成5个步骤: 1:提供表名 2:提供schema 3:提供主键 4:定义重要选项:例如:定义分区的schema 5:调用create Table a ...
- eclipse中设置自动生成的author,date等注释
转自:http://blog.csdn.net/zhouhong1026/article/details/38396311 转自:http://hi.baidu.com/qianjian21/blog ...
- rest模式get,post,put,delete简单讲解
1.请求方法为get时,会向数据库请求数据,类似于select语言,只能达到查询的效果,不会添加,修改,不会影响资源的内容,无副作用 2.请求方法为post时,该方法,用于向服务器添加数据,可以改变数 ...
- Maya cmds pymel 获取安装选择顺序选择的物体
Maya cmds pymel 获取安装选择顺序选择的物体 import maya.cmds as cmds 先设置选择顺序 cmds.selectPref(trackSelectionOrder = ...
- Context家族
--摘自<android插件化开发指南> 1.ContextWrapper只是一个包装类,没有任何具体的实现,真正的逻辑都在ContextImpl里面 2.应用程序中包含多个Context ...
- Spring AOP 切面编程实战Demo项目
为什么会有此项目?在某日,我看博客时,看到了讲面向切面编程的内容,之前也知道spring是面向切面编程的,只是自己没有写过相关的代码,于是决定自己写一个test.但是url拦截器从外部看,和AOP有相 ...
- Xamarin Essentials教程安全存储SecureStorage
Xamarin Essentials教程安全存储SecureStorage 在实际应用中,应用程序会将一些数据保存在用户设备中,避免用户重复操作.但是为了防止因设备丢失或者感染病毒导致数据泄漏,需 ...
- centos安装ES(elasticsearch)
1.下载(版本为elasticsearch-6.5.4): https://www.elastic.co/downloads/elasticsearch 2.上传至服务/user/local目录 3. ...
- node+express跨域处理