#FT0000014. Rải sỏi (Spread)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Rải sỏi (Spread)
Spread
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
Bob has piles of stones arranged in a row and numbered from to . Initially, each pile contains exactly stones. He may distribute additional stones to a consecutive set of piles or inspect a single pile.
Command S u v k adds stones to every pile from to , inclusive. It does not distribute only stones in total: over piles, the total number of stones increases by .
Command Q p requests the current number of stones in pile . All earlier distributions remain in effect. Queries only observe the state and do not change it.
Input
- Line 1:
n m cgives number of piles, commands, and initial stones per pile. - Next lines: each line contains one of the following commands, in execution order:
S u v k: add stones to each pile from through .Q p: query the stones in pile .
Output
For each Q p command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- .
Subtask 2 (30 points):
- .
- .
- .
- .
- .
Subtask 3 (50 points):
- .
- .
- .
- .
- .
Examples
Input
7 5 0
Q 7
S 1 7 1
Q 3
S 1 3 1
Q 3
Output
0
1
2
Explanation
There are elements. The initial values are [0, 0, 0, 0, 0, 0, 0].
-
Command 1 —
Q 7: Pile contains stones, so print0. -
Command 2 —
S 1 7 1: Add stones to each pile in ; state:[1, 1, 1, 1, 1, 1, 1]. -
Command 3 —
Q 3: Pile contains stones, so print1. -
Command 4 —
S 1 3 1: Add stones to each pile in ; state:[2, 2, 2, 1, 1, 1, 1]. -
Command 5 —
Q 3: Pile contains stones, so print2.
Collect the answers to output-producing commands in their input order, printing one answer per line.