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

#FT0000230. Thao tác với các màu (Colorful Operations)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thao tác với các màu (Colorful Operations)

Colorful Operations

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array has nn elements a1,…,ana_1,\ldots,a_n; each element has a value and a color. Initially all values are 00, all colors are 11, and the available colors are numbered 11 through nn.

Process qq operations in order:

  • Color l r c: set the colors of all positions from ll to rr to cc, preserving their current numerical values.
  • Add c x: add integer xx (possibly negative) to every element currently colored cc, regardless of position. Elements that only acquire color cc later do not retroactively receive past additions.
  • Query i: print the current numerical value at position ii.

Changing colors affects which elements receive future additions but never alters the additions already made.

Input

  • The first line contains n,qn,q, the array length and number of commands.
  • Each of the next qq lines contains one command in exactly one of these forms: Color l r c, Add c x, or Query i.

Output

For each Query i command, print one line containing the current numerical value of aia_i, in command order.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤201\le n,q\le20; Color: 1≤l≤r≤n1\le l\le r\le n, 1≤c≤n1\le c\le n; Add: 1≤c≤n1\le c\le n, −109≤x≤109-10^9\le x\le10^9; Query: 1≤i≤n1\le i\le n.

  • Subtask 2 (30 points): 1≤n,q≤20001\le n,q\le2000; Color: 1≤l≤r≤n1\le l\le r\le n, 1≤c≤n1\le c\le n; Add: 1≤c≤n1\le c\le n, −109≤x≤109-10^9\le x\le10^9; Query: 1≤i≤n1\le i\le n.

  • Subtask 3 (50 points): 1≤n,q≤1061\le n,q\le10^6; Color: 1≤l≤r≤n1\le l\le r\le n, 1≤c≤n1\le c\le n; Add: 1≤c≤n1\le c\le n, −109≤x≤109-10^9\le x\le10^9; Query: 1≤i≤n1\le i\le n.

Examples

Input

5 8
Color 2 4 2
Add 2 2
Query 3
Color 4 5 3
Color 2 2 3
Add 3 3
Query 2
Query 5

Output

2
5
3

Explanation

All five positions start at value zero and color 11. The first Color command makes positions 2,3,42,3,4 color 22; Add 2 2 increases these values to 22, so Query 3 prints 2. Then positions 4,54,5, followed by position 22, are recolored to 33 without changing their values. Add 3 3 adds three to positions 2,4,52,4,5, giving value 55 at position 22 and value 33 at position 55. The final queries therefore print 5 and 3.