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

#SRD0000029. Biến đổi mảng theo truy vấn (Array Transformer)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Biến đổi mảng theo truy vấn (Array Transformer)

Array Transformer

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array A1,…,AnA_1,\ldots,A_n, a positive integer uu, and mm transformation instructions. Each instruction (L,R,v,p)(L,R,v,p) acts on the current array:

  1. Count kk elements in inclusive interval [L,R][L,R] that are strictly less than vv.
  2. Assign $A_p=\left\lfloor\dfrac{u\cdot k}{R-L+1}\right\rfloor$.

The updated position pp may lie inside or outside [L,R][L,R]. Print the final array after all instructions.

Input

The first line contains n,m,un,m,u. The next nn values describe AiA_i. Each of the following mm lines contains L,R,v,pL,R,v,p.

Output

Print exactly nn lines; line ii contains the final value of AiA_i.

Subtasks

  • Subtask 1 (10 points): 1≤n≤601\le n\le 60; 1≤m≤801\le m\le 80; 1≤u≤1091\le u\le10^9; initially 1≤Ai≤u1\le A_i\le u; 1≤L≤R≤n1\le L\le R\le n; 1≤v≤u1\le v\le u; 1≤p≤n1\le p\le n. Values resulting from updates may be zero.
  • Subtask 2 (20 points): 1≤n≤20001\le n\le 2000; 1≤m≤10001\le m\le 1000; 1≤u≤1091\le u\le10^9; initially 1≤Ai≤u1\le A_i\le u; 1≤L≤R≤n1\le L\le R\le n; 1≤v≤u1\le v\le u; 1≤p≤n1\le p\le n. Values resulting from updates may be zero.
  • Subtask 3 (30 points): 1≤n≤200001\le n\le 20000; 1≤m≤120001\le m\le 12000; 1≤u≤1091\le u\le10^9; initially 1≤Ai≤u1\le A_i\le u; 1≤L≤R≤n1\le L\le R\le n; 1≤v≤u1\le v\le u; 1≤p≤n1\le p\le n. Values resulting from updates may be zero.
  • Subtask 4 (40 points): 1≤n≤3000001\le n\le 300000; 1≤m≤500001\le m\le 50000; 1≤u≤1091\le u\le10^9; initially 1≤Ai≤u1\le A_i\le u; 1≤L≤R≤n1\le L\le R\le n; 1≤v≤u1\le v\le u; 1≤p≤n1\le p\le n. Values resulting from updates may be zero.

Examples

Input

10 1 11
1
2
3
4
5
6
7
8
9
10
2 8 6 10

Output

1
2
3
4
5
6
7
8
9
6

Explanation

The sample examines [2,8][2,8] with threshold 66 and finds four smaller values 2,3,4,52,3,4,5. Since u=11u=11 and the interval length is 77, assign A10=⌊11⋅4/7⌋=6A_{10}=\lfloor 11\cdot4/7\rfloor=6. All other positions remain unchanged.