Reactor

시간 제한7초메모리 제한2048 MB

요약
여러 원자로에 범위 압력 증가 연산을 적용하며, 압력이 한계에 도달하면 배출되고 한계가 절반으로 줄어들 때, 범위 내 총 배출 횟수를 구한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 이분 탐색, 구현, 수학
정답자
아직 제출이 없습니다

문제

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 nn reactors. Each reactor, indexed from 11 to nn, has an initial maximum pressure limit p_ip\_i. All of the reactors’ initial pressure are 00. The system must support two types of operations:

  1. Pressure Increase Operation: For a given range of reactors \[l,r]\[l, r], increase their pressure by kk units. If the pressure of any reactor in this range reaches or exceeds its maximum limit, it will vent, resetting its pressure to 00. And the maximum pressure limit of the vented reactor will be updated to max⁡(⌊P_old2⌋,1)\max{(\left\lfloor \frac{P\_{old}}{2} \right\rfloor, 1)}, where p_oldp\_{old} is the maximum pressure limit of the reactor before the current pressure increase operation.
  2. Venting Count Query: For a given range of reactors \[l,r]\[l, r], 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 nn and qq, representing the number of reactors and the number of operations, respectively.

The second line contains nn integers, the ii-th integer p_ip\_i represents the initial maximum pressure limit of the ii-th reactor.

The following qq lines describe the operations. Each line begins with an integer opop.

  • If op=1op = 1, it is followed by three integers ll, rr, and kk, representing a pressure increase operation on the range of reactors from ll to rr (inclusive) by kk units.
  • If op=2op = 2, it is followed by two integers ll and rr, representing a venting count query for the range of reactors from ll to rr (inclusive).

출력

For each query that op=2op = 2, 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.

제한

  • 1≤n≤2×1051 ≤ n ≤ 2 \times 10^5
  • 1≤q≤2×1051 ≤ q ≤ 2 \times 10^5
  • 1≤p_i≤4×1051 ≤ p\_i ≤ 4 \times 10^5
  • 1≤l≤r≤n1 ≤ l ≤ r ≤ n
  • 1≤k≤4×1051 ≤ k ≤ 4 \times 10^5
  • It is guaranteed that there is at least one Venting Count Query.

예제3

  1. 예제 1

    입력
    10 5
    5 10 23 45 10 45 65 10 68 9
    1 5 10 664
    1 2 9 5
    2 4 10
    1 8 8 5
    2 1 10
    
    예상 출력
    8
    9
    
  2. 예제 2

    입력
    10 10
    79 26 9 28 13 40 26 54 69 19
    1 1 5 6
    1 5 7 2
    2 4 7
    1 9 10 19
    2 5 7
    1 5 7 27
    2 10 10
    2 9 9
    1 6 6 20
    1 3 8 6
    
    예상 출력
    0
    0
    1
    0
    
  3. 예제 3

    입력
    10 10
    56 29 49 42 47 21 23 54 8 31
    2 9 9
    1 5 6 23
    2 6 7
    2 4 7
    1 5 6 68
    2 1 9
    2 3 6
    1 2 10 89
    2 6 8
    1 3 6 53
    
    예상 출력
    0
    1
    1
    3
    3
    5