#FT0000230. Thao tác với các màu (Colorful Operations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 elements ; each element has a value and a color. Initially all values are , all colors are , and the available colors are numbered through .
Process operations in order:
Color l r c: set the colors of all positions from to to , preserving their current numerical values.Add c x: add integer (possibly negative) to every element currently colored , regardless of position. Elements that only acquire color later do not retroactively receive past additions.Query i: print the current numerical value at position .
Changing colors affects which elements receive future additions but never alters the additions already made.
Input
- The first line contains , the array length and number of commands.
- Each of the next lines contains one command in exactly one of these forms:
Color l r c,Add c x, orQuery i.
Output
For each Query i command, print one line containing the current numerical value of , in command order.
Subtasks
-
Subtask 1 (20 points): ;
Color: , ;Add: , ;Query: . -
Subtask 2 (30 points): ;
Color: , ;Add: , ;Query: . -
Subtask 3 (50 points): ;
Color: , ;Add: , ;Query: .
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 . The first Color command makes positions color ; Add 2 2 increases these values to , so Query 3 prints 2. Then positions , followed by position , are recolored to without changing their values. Add 3 3 adds three to positions , giving value at position and value at position . The final queries therefore print 5 and 3.