PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000014. Rải sỏi (Spread)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rải sỏi (Spread)

Spread

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

Bob has nn piles of stones arranged in a row and numbered from 11 to nn. Initially, each pile contains exactly cc stones. He may distribute additional stones to a consecutive set of piles or inspect a single pile.

Command S u v k adds kk stones to every pile from uu to vv, inclusive. It does not distribute only kk stones in total: over v−u+1v-u+1 piles, the total number of stones increases by k(v−u+1)k(v-u+1).

Command Q p requests the current number of stones in pile pp. All earlier distributions remain in effect. Queries only observe the state and do not change it.

Input

  • Line 1: n m c gives number of piles, commands, and initial stones per pile.
  • Next mm lines: each line contains one of the following commands, in execution order:
    • S u v k: add kk stones to each pile from uu through vv.
    • Q p: query the stones in pile pp.

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):

  • 1≤n≤241\le n\le 24.
  • 1≤m≤301\le m\le 30.
  • 0≤c,k≤1090\le c,k\le 10^9.
  • 1≤u≤v≤n1\le u\le v\le n.
  • 1≤p≤n1\le p\le n.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤m≤16001\le m\le 1600.
  • 0≤c,k≤1090\le c,k\le 10^9.
  • 1≤u≤v≤n1\le u\le v\le n.
  • 1≤p≤n1\le p\le n.

Subtask 3 (50 points):

  • 1≤n≤10000001\le n\le 1000000.
  • 1≤m≤2500001\le m\le 250000.
  • 0≤c,k≤1090\le c,k\le 10^9.
  • 1≤u≤v≤n1\le u\le v\le n.
  • 1≤p≤n1\le p\le n.

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 n=7n=7 elements. The initial values are [0, 0, 0, 0, 0, 0, 0].

  1. Command 1 — Q 7: Pile 77 contains 00 stones, so print 0.

  2. Command 2 — S 1 7 1: Add 11 stones to each pile in [1,7][1,7]; state: [1, 1, 1, 1, 1, 1, 1].

  3. Command 3 — Q 3: Pile 33 contains 11 stones, so print 1.

  4. Command 4 — S 1 3 1: Add 11 stones to each pile in [1,3][1,3]; state: [2, 2, 2, 1, 1, 1, 1].

  5. Command 5 — Q 3: Pile 33 contains 22 stones, so print 2.

Collect the answers to output-producing commands in their input order, printing one answer per line.