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

  1. 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

    题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...

  2. Codeforces Round #470 Div. 2题解

    A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. 【二分答案】Codeforces Round #402 (Div. 2) D. String Game

    二分要删除几个,然后暴力判定. #include<cstdio> #include<cstring> using namespace std; int a[200010],n, ...

  4. Codeforces Round #470 Div. 1

    A:暴力枚举x2的因子,由此暴力枚举x1,显然此时减去其最大质因子并+1即为最小x0. #include<iostream> #include<cstdio> #include ...

  5. 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 ...

  6. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  7. 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) ...

  8. 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 ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. bzoj 松鼠的新家

    哈夫曼距离与切比雪夫距离的转化

  2. Java程序编译和运行过程之 一个对象的生命之旅(类加载和类加载器)

    Java程序从创建到运行要经过两个大步骤 1:源文件(.java)由编译器编译成字节码ByteCode(.class) 2:字节码由Java虚拟机解释并运行 源文件编译成字节码,主要分成两个部分: 1 ...

  3. Android ADB命令教程二——ADB命令详解

    Android ADB命令教程二——ADB命令详解 转载▼ 原文链接:http://www.tbk.ren/article/249.html       我们使用 adb -h 来看看,adb命令里面 ...

  4. Servlet解决中文乱码问题

    request.setCharacterEncoding("UTF-8"); 并且把这句话放在request.getParameter()之前

  5. Java中字符串比较的问题

    package com.hxl; import java.util.Scanner; public class Test { public static void main(String[] args ...

  6. tomcat多端口配置

    <?xml version="1.0" encoding="UTF-8"?> <Server port="8005" sh ...

  7. 牛客练习赛A 【BFS】

    <题目链接> 题目大意: 给出一张图,问你其中 ' # ' 加上那些不能够到达边界的 ' . ' 的点的个数,' # ' 会起阻挡作用. 解题分析: 本题很好做,无非就是将所有能够由边界上 ...

  8. HDU 4185 Oil Skimming 【最大匹配】

    <题目链接> 题目大意: 给你一张图,图中有 '*' , '.' 两点,现在每次覆盖相邻的两个 '#' ,问最多能够覆盖几次. 解题分析: 无向图二分匹配的模板题,每个'#'点与周围四个方 ...

  9. python之迭代器与生成器

    python之迭代器与生成器 可迭代 假如现在有一个列表,有一个int类型的12345.我们循环输出. list=[1,2,3,4,5] for i in list: print(i) for i i ...

  10. Linux学习之日志管理(二十一)

    Linux学习之日志管理 目录 日志管理 日志服务 rsyslogd的新特点 启动日志服务 常见日志的作用 日志文件的一般格式 rsyslogd日志服务 /etc/rsyslog.conf配置文件 服 ...