CF627B.Factory Repairs
普及+/提高
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一家工厂大批量生产顶针。通常情况下,它每天最多可生产 a 个顶针。然而,部分机器存在缺陷,因此目前每天仅能生产 b 个顶针。工厂计划选择一个持续 k 天的时段进行设备维护与改造;在此期间无法生产任何顶针,但 k 天结束后,其生产能力将恢复至每天 a 个顶针。
初始时没有任何待处理订单。工厂会陆续收到形如 di, ai 的更新信息,表示在第 di 天新增了 ai 个订单。每个订单要求恰好在指定日期当天生产一个顶针。工厂可在单日选择完成任意数量(包括零个)的订单。
随着订单不断到达,工厂主希望了解:若从某给定日期 pi 开始进行维修,他最多能完成多少订单。请帮助工厂主回答他的问题。
输入格式
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 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.
第一行包含五个整数 n、k、a、b 和 q(1 ≤ k ≤ n ≤ 200000,1 ≤ b < a ≤ 10000,1 ≤ q ≤ 200000),分别表示天数、维修时长、工厂的生产速率(即正常日产量 a 和维修日产量 b),以及更新操作的次数。
接下来的 q 行描述了各查询。每个查询为以下两种形式之一:
1 d_i a_i(1 ≤ di ≤ n,1 ≤ ai ≤ 10000):表示在第 di 天新增 ai 个订单;2 p_i(1 ≤ pi ≤ n − k + 1):表示一个询问:当前时刻,若工厂决定从第 pi 天开始进行为期 k 天的维修,则最多能完成多少个订单?
保证输入中至少包含一个第二类查询。
输出格式
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.
对于每个第二类查询,请输出一行,包含一个整数——工厂在所有 n 天内最多能完成的订单数量。
输入输出样例
输入#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.
考虑第一个样例。
我们目前每天最多生产 1 个顶针,维修后每天最多生产 2 个顶针。维修耗时 2 天。
对于第一个问题:我们可以在第 1 天完成 1 笔订单;第 2 天和第 3 天处于维修期,无法完成任何订单;第 4 天没有客户下单,因此也无订单可完成;第 5 天受限于当日产能,最多完成 2 笔订单。综上,共完成 3 笔订单。
对于第三个问题:我们可以在第 1 天完成 1 笔订单,第 2 天完成 1 笔订单,第 5 天完成 2 笔订单,总计完成 4 笔订单。
输入解题思路,AI测评打分。不知道怎么写?