Reactor
시간 제한7초메모리 제한2048 MB
여러 원자로에 범위 압력 증가 연산을 적용하며, 압력이 한계에 도달하면 배출되고 한계가 절반으로 줄어들 때, 범위 내 총 배출 횟수를 구한다.
문제
In a high-tech industrial facility, a series of nuclear reactors are arranged in a linear configuration. Each reactor operates under strict pressure regulations to ensure safety and efficiency. To prevent critical failures, each reactor has a specific maximum pressure limit. When a reactor’s internal pressure reaches or exceeds this limit, a controlled pressure release (venting) is initiated. This system requires sophisticated management due to dynamic operational adjustments and the need for continuous monitoring.
You are tasked with designing and implementing a system to manage the pressure of a line of reactors. Each reactor, indexed from to , has an initial maximum pressure limit . All of the reactors’ initial pressure are . The system must support two types of operations:
- Pressure Increase Operation: For a given range of reactors , increase their pressure by units. If the pressure of any reactor in this range reaches or exceeds its maximum limit, it will vent, resetting its pressure to . And the maximum pressure limit of the vented reactor will be updated to , where is the maximum pressure limit of the reactor before the current pressure increase operation.
- Venting Count Query: For a given range of reactors , you need to report the total number of venting operations that have occurred among all reactors within this specified range since the beginning of the system’s operation.
입력
The first line contains two integers and , representing the number of reactors and the number of operations, respectively.
The second line contains integers, the -th integer represents the initial maximum pressure limit of the -th reactor.
The following lines describe the operations. Each line begins with an integer .
- If , it is followed by three integers , , and , representing a pressure increase operation on the range of reactors from to (inclusive) by units.
- If , it is followed by two integers and , representing a venting count query for the range of reactors from to (inclusive).
출력
For each query that , print a single integer on a new line, representing the total number of venting operations that have occurred among all reactors within the specified range since the beginning of the system’s operation.
제한
- It is guaranteed that there is at least one Venting Count Query.