Make 'em One

4

2 votes
Medium
Problem

All might is the number one hero, but Bakugo doubts his strength. So, to test it, he has given All might a sequence of N stetchable sticks.

Now he has given him Q tasks, each one states that given the original sequence of sticks, stretch(or compress) each stick from Lth stick to Rth stick and make their length equal to K. It takes 1 sec to inc/dec length of a stick and total time is sum of time taken for all the stciks in the given range.

All Might
All might

Note: For each task, starting lengths is the initial lengths given by Bakugo.

 

Input Format:

First line contains N and Q, number of sticks and number of tasks respectively.

Second line contains the lengths of sticks in the order given by Bakugo.

Each of the next Q lines contains L, R and K, denoting the task.

 

Output Format:

Print output for each task in separate lines.

 

Constraints:

1N,Q2105

1lengths106

1L,RN

1K106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first task, initial lengths are {5, 3, 4}.

For second task, initial lengths are {1, 5, 3}.

For this task, initial lengths are {1, 5, 3, 4, 5}.

Editor Image

?