#SGM0000003. Biến trở (Potentiometers)
Biến trở (Potentiometers)
Potentiometers
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are potentiometers arranged from to . Each value is a resistance in Ohms, and the resistance of a contiguous series is the sum of its values. Process point assignments and range measurements.
Input
- The first line contains and : the number of potentiometers and operations.
- The second line contains initial resistances, each from to .
- Each of the next lines is
S x r, which sets position to , orM x y, which asks for the sum from through , where .
Output
For every M operation, print the measured range sum.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: .
Examples
Input
3 6
100 100 100
M 1 1
M 1 3
S 2 200
M 1 2
S 3 0
M 2 3
Output
100
300
300
200
Explanation
The three initial values are all . The first two measurements are and . After setting position to , the sum on is . After setting position to , the sum on is .