303222: CF627B. Factory Repairs

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Factory Repairs

题意翻译

您将获得一个长度为 $n$ 的数组 $t$,另有三个数 $a$,$b$,$k$。初始时数列每一项均为 $0$。 有 $q$ 次操作,每次操作有两种可能: `1 x y`:将 $t_x$ 增加 $y$。 `2 x`:求出 $\left(\sum\limits_{i=1}^{x-1} \min(b,t_i)\right) + \left(\sum\limits_{i=x+k}^{n} \min(a,t_i)\right)$。 您需要在每一次第二种操作后输出正确的答案。 $1 \leq k \leq n \leq 2 \times 10^5$,$1 \leq b < a \leq 10^4$,$1 \leq q \leq 2 \times10^5$。

题目描述

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 $ d_{i} $ , $ a_{i} $ , indicating that $ a_{i} $ new orders have been placed for the $ d_{i} $ -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 $ p_{i} $ . Help the owner answer his questions.

输入输出格式

输入格式


The first line contains five integers $ n $ , $ k $ , $ a $ , $ b $ , and $ q $ ( $ 1<=k<=n<=200000 $ , $ 1<=b&lt;a<=10\ 000 $ , $ 1<=q<=200000 $ ) — 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\ d_{i}\ a_{i} $ ( $ 1<=d_{i}<=n $ , $ 1<=a_{i}<=10\ 000 $ ), representing an update of $ a_{i} $ orders on day $ d_{i} $ , or - $ 2\ p_{i} $ ( $ 1<=p_{i}<=n-k+1 $ ), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day $ p_{i} $ ? It's guaranteed that the input will contain at least one query of the second type.

输出格式


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.

输入输出样例

输入样例 #1

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

输出样例 #1

3
6
4

输入样例 #2

5 4 10 1 6
1 1 5
1 5 5
1 3 2
1 5 2
2 1
2 2

输出样例 #2

7
1

说明

Consider the first sample. We produce up to $ 1 $ thimble a day currently and will produce up to $ 2 $ thimbles a day after repairs. Repairs take $ 2 $ days. For the first question, we are able to fill $ 1 $ order on day $ 1 $ , no orders on days $ 2 $ and $ 3 $ since we are repairing, no orders on day $ 4 $ since no thimbles have been ordered for that day, and $ 2 $ orders for day $ 5 $ since we are limited to our production capacity, for a total of $ 3 $ orders filled. For the third question, we are able to fill $ 1 $ order on day $ 1 $ , $ 1 $ order on day $ 2 $ , and $ 2 $ orders on day $ 5 $ , for a total of $ 4 $ orders.

Input

题意翻译

您将获得一个长度为 $n$ 的数组 $t$,另有三个数 $a$,$b$,$k$。初始时数列每一项均为 $0$。 有 $q$ 次操作,每次操作有两种可能: `1 x y`:将 $t_x$ 增加 $y$。 `2 x`:求出 $\left(\sum\limits_{i=1}^{x-1} \min(b,t_i)\right) + \left(\sum\limits_{i=x+k}^{n} \min(a,t_i)\right)$。 您需要在每一次第二种操作后输出正确的答案。 $1 \leq k \leq n \leq 2 \times 10^5$,$1 \leq b < a \leq 10^4$,$1 \leq q \leq 2 \times10^5$。

加入题单

算法标签: