zoukankan      html  css  js  c++  java
  • 8VC Venture Cup 2016

    D. Factory Repairs

    题目连接:

    http://www.codeforces.com/contest/635/problem/D

    Description

    A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.

    Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.

    As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.

    Input

    The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.

    The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:

    1 di ai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or
    2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
    It's guaranteed that the input will contain at least one query of the second type.

    Output

    For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days.

    Sample Input

    5 2 2 1 8
    1 1 2
    1 5 3
    1 2 1
    2 2
    1 4 2
    1 3 2
    2 1
    2 3

    Sample Output

    3
    6
    4

    Hint

    题意

    最多n天,然后你每天普通情况下可以产生b个东西,好的情况下可以产生b个东西

    由普通的情况到好的情况需要k天的休息,就这k天啥也干不了

    q次询问

    现在你有两个操作

    1 x y,第x天需要y个东西(不独立)

    2 x 在第x天进行休息,然后问你最多能够满足多少个东西的需求(独立的)

    题解:

    树状数组就好了

    k天以前的,我就每个点的最大值就是b

    k天以后,每个点的最大值是a

    然后维护一下区间和就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn =  2e5+7;
    int n,k,a,b,q;
    int c[maxn][2];
    int A[maxn];
    int lowbit(int x)
    {
        return x&(-x);
    }
    void update(int x,int y,int z)
    {
        for(int i=x;i<maxn;i+=lowbit(i))
            c[i][z]+=y;
    }
    int getsum(int x,int z)
    {
        int ans = 0;
        for(int i=x;i;i-=lowbit(i))
            ans+=c[i][z];
        return ans;
    }
    int main()
    {
        scanf("%d%d%d%d%d",&n,&k,&a,&b,&q);
        for(int i=1;i<=q;i++)
        {
            int op;scanf("%d",&op);
            if(op==1)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                int p1 = A[x];A[x]+=y;
                update(x,min(b,A[x])-min(b,p1),0);
                update(x,min(a,A[x])-min(a,p1),1);
            }
            else
            {
                int x;scanf("%d",&x);
                printf("%d
    ",getsum(x-1,0)+getsum(n,1)-getsum(x+k-1,1));
            }
        }
    }
  • 相关阅读:
    【科创人上海行】扶墙老师王福强:架构师创业要突破思维局限,技术人创业的三种模式,健康第一
    【科创人·独家】连续创业者高春辉的这六年:高强度投入打造全球领先的IP数据库
    中国确实需要大力扩充核武器
    SAP MM 可以通过STO在公司间转移质检库存?
    SAP MM 如何看一个采购申请是由APO系统创建后同步过来的?
    SAP MM 如何看一个Inbound Delivery单据相关的IDoc?
    SAP ECC & APO集成
    SAP MM 采购订单收货之后自动形成分包商库存?
    SAP MM 带有'Return'标记的STO,不能创建内向交货单?
    SAP MM 没有启用QM的前提下可以从QI库存里退货给Vendor?
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5233244.html
Copyright © 2011-2022 走看看