#P11217. 【MX-S4-T1】「yyOI R2」youyou 的垃圾桶

【MX-S4-T1】「yyOI R2」youyou 的垃圾桶

Background

Original link: https://oier.team/problems/S4A

Problem Description

There are nn trash cans, and they attack youyou. The initial attack power of the ii-th trash can is a positive integer aia_i. youyou's initial health is a positive integer WW.

Define the following process as one battle:

  • Starting from trash can 11, each trash can attacks in order. When the ii-th trash can attacks, youyou's health WW decreases by aia_i, and then in this battle the ii-th trash can's attack power aia_i doubles. After the nn-th trash can finishes its attack, repeat this process.

When W0W \le 0, i.e. when youyou dies, this battle ends immediately. Then reset youyou's health WW and all trash cans' attack power aia_i to the values before this battle.

The score of this battle is defined as the number of times youyou is attacked by trash cans (not including the attack that kills youyou exactly).

Now there are qq battles in total. For each battle, three numbers l,r,dl, r, d are given, meaning that you first strengthen the trash cans in [l,r][l, r], increasing their initial attack power aia_i by dd, and then run a battle. You need to tell youyou the score of this battle.

The increases to the trash cans' initial attack power before each battle will affect all subsequent battles.

Input Format

The first line contains three integers n,q,Wn, q, W, representing the number of trash cans, the number of battles, and the health.

The second line contains nn integers. The ii-th number represents the attack power aia_i of the ii-th trash can before all battles.

The next qq lines each contain three integers l,r,dl, r, d, representing the strengthening parameters before the ii-th battle.

Output Format

Output qq lines in total. The ii-th line outputs one number sis_i, representing the score of the ii-th battle.

6 4 75
9 1 4 5 1 4
1 1 1
3 5 3
3 5 1
3 5 3

11
9
8
8

Hint

Sample Explanation #1

The strengthenings before the four battles are:

  • Increase the attack power of trash cans in [1,1][1, 1] by 11.
  • Increase the attack power of trash cans in [3,5][3, 5] by 33.
  • Increase the attack power of trash cans in [3,5][3, 5] by 11.
  • Increase the attack power of trash cans in [3,5][3, 5] by 33.

In the first battle, the initial attack powers of the trash cans are 10,1,4,5,1,410, 1, 4, 5, 1, 4.

youyou is first attacked once by each of these trash cans in order, and the remaining health is 5050. The trash cans' attack power becomes 20,2,8,10,2,820, 2, 8, 10, 2, 8.

Next, youyou is attacked by the first trash can, and the remaining health is 3030.

After being attacked by the second trash can, the remaining health is 2828.

After being attacked by the third trash can, the remaining health is 2020.

And so on. When attacked by the sixth trash can, the remaining health becomes 00. Since the lethal attack is not counted, youyou received a total of 6+5=116 + 5 = 11 attacks.

In the second battle, the initial attack powers of the trash cans are 10,1,7,8,4,410, 1, 7, 8, 4, 4.

In the third battle, the initial attack powers of the trash cans are 10,1,8,9,5,410, 1, 8, 9, 5, 4.

In the fourth battle, the initial attack powers of the trash cans are 10,1,11,12,8,410, 1, 11, 12, 8, 4.

It can be concluded that the scores of battles 242 \sim 4 are 9,8,89, 8, 8, respectively.

Sample #2

See the attached wxyt/wxyt2.in and wxyt/wxyt2.ans.

This sample satisfies the constraints of test points 141 \sim 4.

Sample #3

See the attached wxyt/wxyt3.in and wxyt/wxyt3.ans.

This sample satisfies the constraints of test points 131413 \sim 14.

Sample #4

See the attached wxyt/wxyt4.in and wxyt/wxyt4.ans.

This sample satisfies the constraints of test points 152015 \sim 20.

Constraints

This problem has 2020 test points, each worth 55 points.

Test Point ID nn qq
141 \sim 4 2×105\le 2 \times 10^5 10\le 10
575 \sim 7 103\le 10^3
8108 \sim 10 105\le 10^5
111211 \sim 12 3×103\le 3 \times 10^3
131413 \sim 14 106\le 10^6
152015 \sim 20 2×105\le 2 \times 10^5

For all data, it is guaranteed that 1n2×1051 \le n \le 2 \times 10^5, 1q1061 \le q \le 10^6, 1W10181 \le W \le 10^{18}, 1ai1061 \le a_i \le 10^{6}, 1lrn1 \le l \le r \le n, 1d2151 \le d \le 2^{15}

Translated by ChatGPT 5