#FT0000214. Tổng sau khi chặn giá trị (Clamp)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng sau khi chặn giá trị (Clamp)
Clamp
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an integer sequence , with positions numbered from to . Process queries in order. Each query has one of the following forms:
1 x y: Replace the value at position with . All other positions remain unchanged.2 l r: For every current element , compute , and output the sum of these results over .
In this expression, selects the smaller of and ; then selects the larger of and that result.
The input does not guarantee . In particular, if , each summand equals . Only a type-1 query changes ; a type-2 query does not modify the sequence.
Input
- The first line contains : the array length and the number of queries.
- The second line contains exactly integers .
- Each of the following lines is either
1 x yor2 l r, as described above. Position is -based.
Output
For every type-2 query, print one line containing , evaluated using the current sequence. Preserve the order of type-2 queries.
Subtasks
- Subtask 1 (20 points): ; ; for every ; type
1has and ; type2has (without requiring ). - Subtask 2 (30 points): ; ; for every ; type
1has and ; type2has (without requiring ). - Subtask 3 (50 points): ; ; for every ; type
1has and ; type2has (without requiring ).
Examples
Input
3 4
4 3 2
1 1 7
2 3 5
1 2 0
2 4 2
Output
11
12
Explanation
Initially, . Query 1 1 7 changes the first element to , giving . For query 2 3 5, the contributions are , , and . Their sum is , giving the first output line.
Next, 1 2 0 changes the sequence to . The final query is 2 4 2, where . For any element, , so each clamped contribution is . Since there are elements, the sum is , giving the second output line.