Tropical Bananas

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem types

The Tropical Banana, also known as the Musa verylongnamea, is a delicacy known all over the otherworld. However there is one thing about the Musa verylongnamea that most people do not know: this specific type of banana is extremely picky and will refuse to grow unless heaps and heaps of fertilizer are dumped all over the place it grows, a place known as The Infernal Isles.

With the early retirement of the previous Keeper of Bananas, Florence has been chosen to groom those bananas to perfection. This would normally be an extremely joyous event because of the exorbitant pay, however, there are two problems: she has no idea how to fertilize Tropical Bananas, and each spray of the TURF BUILDER 999 PRO launches layers of fertilizer all over the place. The Infernal Isles is made up of N separate columns of soil, each originally starting with 0 layers of fertilizer. Florence can do one of two tricks with the TURF BUILDER 999 PRO: she can spray column l to r, adding a+b1 layers to column l, a+b2 layers to column l+1, and so on until column r where she adds a+b(rl+1) layers. Otherwise, she can do the opposite, spraying column l to r and adding a+b1 layers to column r, a+b2 layers to column r1 and so on until column l where she adds a+b(rl+1) layers. Specifically, there are two operations where:

0 l r a b - for all i between l and r inclusive, increase coli by a+b(il+1).

1 l r a b - for all i between l and r inclusive, increase coli by a+b(ri+1).

In fact, the TURF BUILDER 999 PRO is so powerful that it can remove layers of fertilizer and may even cause some columns to have a negative amount of layers of fertilizer! Don't ask what this means, since Florence doesn't know either. She needs to record the number of layers of fertilizer at each column in order to efficiently grow Tropical Bananas, but unfortunately speed math is not her strong suit. Desperate, she asks you, a world renowned Scratch programmer to help her calculate the number of layers of fertilizer at each column after she sprays fertilizer Q times.

For this problem, Python users are recommended to use PyPy over CPython.

Constraints

For all subtasks:

1liriN

Subtask 1 [30%]

1N2000

1Q2000

1000ai,bi1000

Subtask 2 [70%]

1N200000

1Q1000000

100000ai,bi100000

Input Specification

The first line will contain two integers N and Q, representing the number of columns and the number of operations respectively.

Each of the next Q lines will contain an operation in the form of xi, li, ri, ai and bi where xi is either 0 or 1.

Output Specification

Output N lines, the ith line containing the value of coli after all the operations have been applied.

Sample Input 1

Copy
4 5
1 1 4 9 0
1 2 4 10 -7
0 1 2 4 6
0 2 3 3 -9
0 2 3 5 -1

Sample Output 1

Copy
19
12
-7
12

Explanation for Sample 1

The first operation adds 9 to all the elements between index 1 and 4 inclusive. The second operation adds 71+10=3 to index 4, 72+10=4 to index 3 and 73+10=11 to index 2. The third operation adds 4+61=10 to index 1 and 4+62=16 to index 2. Doing all the operations will result in a final list of numbers: 19, 12, 7 and 12.

Sample Input 2

Copy
4 5
0 2 4 45 73
1 3 4 61 -10
0 2 4 96 86
1 4 4 27 23
0 1 2 12 48

Sample Output 2

Copy
60
408
500
719

Explanation for Sample 2

The first operation adds 45+731=118 to index 2, 45+732=191 to index 3 and 45+733=264 to index 4. The second operation adds 101+61=51 to index 4 and 102+61=41 to index 3. Doing all the operations will result in a final list of numbers: 60, 408, 500 and 719.


Comments

There are no comments at the moment.