码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记

时间:2018-03-13 00:59:45      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:个数   names   cstring   back   ++   标记   sed   inf   problem   

题目链接:C. Producing Snow

题意:给两个数组v[N],T[N],v[i]表示第i天造的雪,T[i],表示第i天的温度,一堆雪如果<=T[i],当天就会融完,否则融化T[i],要求输出每天的融雪总量。

题解:我对T数组求个前缀和,就可以二分找到每堆雪在那一天(pos)融化,余下的要加进答案中ans[i],然后用一个an数组在a[i]+1,a[pos]-1,最后求再求一次前缀和.

ans[i]再加上an[i]*t[i].每次操作二分logn,N次操作.复杂度O(nlogn)

#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define pb push_back
#define ll long long
#define PI 3.14159265
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define eps 1e-7
typedef unsigned long long ull;
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
const int root=1e6+7;
using namespace std;
ll n,m,s;
ll v[maxn],t[maxn],an[maxn],su[maxn],ans[maxn];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)scanf("%lld",&v[i]);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&t[i]);
        su[i]=su[i-1]+t[i];
    }
    for(int i=1;i<=n;i++)
    {
        int pos=lower_bound(su+1,su+n+1,v[i]+su[i-1])-su;
      //  cout<<pos<<endl;
        ans[pos]+=v[i]+su[i-1]-su[pos-1];
            an[i]+=1;
            an[pos]-=1;
    }
    for(int i=1;i<=n;i++)
    {
        an[i]+=an[i-1];
        ans[i]+=an[i]*t[i];
    }
    for(int i=1;i<=n;i++)
    {
        printf("%lld ",ans[i]);
    }
    puts("");
    return 0;
}

 

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记

标签:个数   names   cstring   back   ++   标记   sed   inf   problem   

原文地址:https://www.cnblogs.com/lhclqslove/p/8552615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!