QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 512 MB Total points: 100

#3245. 搬砖

Statistics

题目背景

张华考上了北京大学;李萍进了中等技术学校;小E在工地搬砖:他们都有光明的前途。

题目描述

温馨提示:请不要模仿小E的搬砖方式,那样很累。

为了能够快乐地搬砖,小E有一种特殊的搬砖方式。

假设他的面前有 $n$​​ 摞砖,他会在一个小时内搬走每一摞砖最上面的 $d$​​ 块。其中 $d$​​ 是小E当前的精力值。如果一摞砖不够 $d$​​​ 块,小E会把这一摞砖剩下的所有砖搬走。

当小E工作完一个小时后发现自己搬完了至少一摞砖,那么他会觉得很快乐,并且继续工作一个小时;但是由于完成了一部分工作,小E可能会产生懈怠的心理,导致精力值有所下降。具体地,对于每一摞砖都有一个属性 $b$,当小E搬完这一摞砖后,精力值就会下降 $b$。

如果没有任何一摞砖被搬完,小E就会停止工作。如果精力值下降到 $0$​​ 或以下,小E也会停止工作。如果小E发现自己需要工作但是所有的砖已被搬完,他会用别的方式来度过这一小时,但这一小时仍算作小E的工作时间。

工地的砖在不停增加,问如果小E初始的精力值为 $d$,那么他可以连续工作几个小时?

输入格式

第一行一个正整数 $T$,表示事件总数。

接下来 $T$ 行,每行若干个整数,其中第一个整数为 $op$ 表示事件类型。

若 $op=1$,则后面跟着两个整数 $a,b$,表示新增了一摞砖,砖有 $a$ 块,搬完后小E的精力值会下降 $b$。

若 $op=2$​,则后面跟着一个正整数 $d$​,询问若小E初始的精力值为 $d$​,那么他可以连续工作几个小时。

注意 $op=2$ 的操作不会改变任何一摞砖的数量。

输出格式

对于每个询问,输出一行一个整数表示答案。

样例1输入

5
1 6 1
1 3 0
1 9 2
2 3
2 4

样例1输出

3
4

样例1解释

第一组询问:

初始有 $3$​ 摞砖,数量分别为 $(6,3,9)$,小E的初始精力是 $3$。

第一个小时,小E在每一摞砖中各搬了 $3$ 块,数量变成 $(3,0,6)$。其中第二摞砖被搬完,小E的精力因此下降 $0$ 并且继续工作一个小时。

第二个小时,小E在每一摞砖中各搬了 $3$​ 块,数量变成 $(0,0,3)$。其中第一摞砖被搬完,小E的精力因此下降 $1$ 并且继续工作一个小时。

第三个小时,小E在每一摞砖中各搬了 $2$ 块,数量变成 $(0,0,1)$。由于没有新的砖摞被搬完,小E停止工作。

第二组询问:

初始有 $3$​ 摞砖,数量分别为 $(6,3,9)$,小E的初始精力是 $4$。

第一个小时,小E在每一摞砖中各搬了 $4$ 块(第二摞砖由于只有 $3$ 块就只搬了 $3$ 块,以下省略),数量变成 $(2,0,5)$。其中第二摞砖被搬完,小E的精力因此下降 $0$ 并且继续工作一个小时。

第二个小时,小E在每一摞砖中各搬了 $4$​​​ 块,数量变成 $(0,0,1)$​​。其中第一摞砖被搬完,小E的精力因此下降 $1$​​ 并且继续工作一个小时。

第三个小时,小E在每一摞砖中各搬了 $3$​​ 块,数量变成 $(0,0,0)$​​。其中第三摞砖被搬完,小E的精力因此下降 $2$ 并且继续工作一个小时。

第四个小时,小E在每一摞砖中各搬了 $1$ 块,但其实此时已经没有砖了,不过这一小时仍然算进小E的工作时间。由于没有新的砖摞被搬完,小E停止工作。

样例2输入

4
1 2 1
2 2
1 2 1
2 2

样例2输出

2
1

样例2解释

第一组询问:

初始有 $1$​ 摞砖,数量为 $2$,小E的初始精力是 $2$。

第一个小时,小E在每一摞砖中各搬了 $2$​​ 块,数量变成 $0$​。这一摞砖被搬完,小E的精力因此下降 $1$​​ 并且继续工作一个小时。

第二个小时,小E在每一摞砖中各搬了 $1$ 块,但其实此时已经没有砖了,不过这一小时仍然算进小E的工作时间。由于没有新的砖摞被搬完,小E停止工作。

第二组询问:

初始有 $2$ 摞砖,数量为 $(2,2)$,小E的初始精力是 $2$。

第一个小时,小E在每一摞砖中各搬了 $2$​ 块, 数量变成 $(0,0)$。两摞砖都被搬完,小E的精力因此下降 $1+1=2$。由于小E的精力下降到 $0$,他停止工作。

子任务

保证 $T\le 351493,1\le op\le 2,1\le a\le 100000,0\le b\le 100000,1\le d \le 100000$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.