Maximize The Value
Time limit2sMemory limit1024 MB
For each position K and operation range [S, T], find the largest sum of X over a contiguous block of operations l to r, counting only operations whose range covers K.
- Level
Medium7 of 10
- Topics
- Segment tree, Prefix sum, Intervals
- Solved
- No attempts yet
Problem
You are given a one-based array of integers: . Initially, the value of each element is .
There are operations, numbered from to . Operation is . When operation is executed, every with increases by .
You must answer independent queries. Each query is , which asks you to choose a range with , then execute operations in order. The answer is the maximum value of after the operations are executed, taken over all possible choices of and .
Input
The first line contains two integers and ().
Each of the next lines contains three integers , , and (; ).
The next line contains an integer ().
Each of the next lines contains three integers , , and (; ).
Output
For each query, print the answer on a separate line.