zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    CDN用户访问调度流程
    最近复习原型 终于明白了一点 写下原型相对比较完美的一种继承方式
    flex布局学习
    Vuex基本使用
    Promise的基本使用
    创建对象的几种方式
    父访问子的数据方法
    购物车案例
    插槽的使用
    ref获取DOM元素
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/8552615.html
Copyright © 2011-2022 走看看