4898: Factory Repairs 工厂维修

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

一家工厂批量生产顶针。通常,它每天最多可以产生一个顶针。但是,有些机器有缺陷,因此目前每天只能产生b顶针。工厂打算选择k天周期进行维护和施工;在此期间它不能产生任何顶针,但在 k 天完成后将恢复到每天完全生产一个顶针。

最初,没有待处理的订单。工厂收到表格 d i, ai 的更新,表明第 i 天已下达 i 新订单。每个订单都需要在指定的日期生产一个顶针。工厂可以选择在单个批次中填写任意数量的订单。

随着订单的到来,工厂主想知道如果他在给定的一天开始维修,他将能够填写的最大订单数量。帮助业主回答他的问题。
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≤kn≤200000, 1≤b<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 di ai (1≤din, 1≤ai≤10 000), representing an update of ai orders on day di, or
  • 2 pi (1≤pin-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.
Examples
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
Output
3
6
4
Input
5 4 10 1 6
1 1 5
1 5 5
1 3 2
1 5 2
2 1
2 2
Output
7
1
Note
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.

输入格式

第一行包含五个整数 n、k、a、b 和 q(1 ≤ k ≤ n ≤ 200,000 ≤ b < a ≤ 1 10,000 ≤ q ≤ 1 200) — 天数、维修时间长度、工厂的生产率和更新次数。

接下来的 q 行包含查询的说明。每个查询采用以下两种形式之一:

1 d i a i (1 ≤ d i ≤ n, 1 ≤ a i ≤ 10 000),代表 i 订单在 d i 天的更新,或
2 p i (1 ≤ pi ≤ n - k + 1),代表一个问题:目前,如果工厂决定在第 PI 天开始维修,可以完成多少订单?
保证输入将至少包含一个第二种类型的查询。

输出格式

对于第二种类型的每个查询,打印一行包含单个整数 — 工厂在所有 n 天内可以填写的最大订单数。

输入样例 复制

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

输出样例 复制

3
6
4

数据范围与提示

考虑第一个示例。

我们目前每天最多生产 1 个顶针,维修后每天最多生产 2 个顶针。维修需要 2 天。

对于第一个问题,我们能够在第 1 天填写 1 个订单,在第 2 天和第 3 天没有订单,因为我们正在维修,在第 4 天没有订单,因为当天没有订购顶针,第 2 天可以填写 5 个订单,因为我们的生产能力有限,总共完成了 3 个订单。

对于第三个问题,我们能够在第 1 天填写 1 个订单,在第 1 天填写 2 个订单,在第 2 天填写 5 个订单,总共 4 个订单。


————————————————
版权声明:本文为CSDN博主「洋-葱」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42505741/article/details/81607656