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

Posted lhclqslove

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记相关的知识,希望对你有一定的参考价值。

题目链接: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+差分标记的主要内容,如果未能解决你的问题,请参考以下文章

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

Codeforces Global Round 19

Codeforces Educational Codeforces Round 67

Codeforces Round 1132Educational Round 61

codeforces Technocup 2017 - Elimination Round 2/Codeforces Round #380 (Div. 2, Rated, Based on Techn

Codeforces Round #705 (Div. 2)