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\n",getsum(x-1,0)+getsum(n,1)-getsum(x+k-1,1));
}
}
}

8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组的更多相关文章

  1. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)

    暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...

  2. 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp

    E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...

  3. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A

    A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学

    C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...

  5. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题

    B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...

  6. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题

    A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...

  7. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题

    http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...

  8. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card

    D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...

  9. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集

    A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. peewee外键性能问题

    # 转载自:https://www.cnblogs.com/miaojiyao/articles/5217757.html 下面讨论一下用peewee的些许提高性能的方法. 避免N+1查询 N+1查询 ...

  2. 從 kernel source code 查出 版本號碼

    kernel/Makefile 1 VERSION = 4 2 PATCHLEVEL = 4 3 SUBLEVEL = 21 4 EXTRAVERSION = 5 NAME = Blurry Fish ...

  3. 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...

  4. telent

    telnet    ip  空格 port ctrl+]  进入 命令后 quit 退出 在linux/unix下使用telnet hostname port连接上主机后会提示Escape chara ...

  5. mybatis spring sqlsession

    sqlsession是什么? 从 http://blog.csdn.net/hupanfeng/article/details/9238127 知道 sqlsession创建 可以看出,创建sqlse ...

  6. memcached安装+绑定访问ip

    安装: 1.由于memcached是基于libevent的,需要安装libevent,libevent-devel $yum -y install libevent libevent-devel 2. ...

  7. 关于在C#对类的属性理解

    在类中都有一些成员.什么是类中的成员呢,我个人理解的是一个类中所应有的属性,方法,字段(因为目前才接触到类.所以类中一些其它应有的东西还不太熟悉),现在只探讨我列举的这几个在类中应有的东西.什么是属性 ...

  8. 使用css让文字两端对齐

    text-align:justify; text-justify:distribute-all-lines; text-align-last:justify;可以让文字实现两端对齐

  9. CentOS7.5右键创建空白文档

    首先我们进入centos7桌面 在桌面上右键“打开终端” 在终端我们使用cd命令进入用户目录下的模板文件夹cd   ~/模板 ---->中文版cd   ~/Templates ---->中 ...

  10. 解决CentOS7.4KDE桌面或者gnome桌面安装VLC及声音问题

    一.安装VLC 1.下载源 https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/e/epel-release-7-11.noarch.rpm http ...