#SGM0000064. Truy vấn đổi hàng loạt (Mass Change Queries)
Truy vấn đổi hàng loạt (Mass Change Queries)
Mass Change Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of integers in the range 1 to 100, process queries l r x y: for every with , replace it by .
After all queries, print the final array.
Input
The first line contains . The second line contains the array. The third line contains . Each of the next lines contains l r x y.
Output
Print the elements after all queries have been processed.
Subtasks
-
Subtask 1 (20%): n,q≤30; all other conditions are unchanged.
-
Subtask 2 (30%): n,q≤3000; all other conditions are unchanged.
-
Subtask 3 (50%): full constraints:
-
-
-
-
Examples
Input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
Output
5 2 5 4 5
Explanation
The three replacements transform the sample array successively to [1,2,5,4,5], then [1,2,1,4,1], and finally [5,2,5,4,5].