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

#PS0000244. Thực hiện hàng loạt thao tác cộng đoạn (Greg and Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thực hiện hàng loạt thao tác cộng đoạn (Greg and Array)

Greg and Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array of nn nonnegative integers is given, together with mm numbered operations. Operation (li,ri,di)(l_i,r_i,d_i) increases every element in its inclusive interval by did_i. Each of kk requests (x,y)(x,y) executes each numbered operation from xx through yy once. Operations may be executed repeatedly by different requests. Print the final array.

Input

First line: n,m,kn,m,k. Second line: nn values aia_i. The next mm lines contain li,ri,dil_i,r_i,d_i, followed by kk lines containing x,yx,y.

Output

Print the final array on one line.

Subtasks

  • Subtask 1 (20 points): 1≤n,m,k≤301\le n,m,k\le 30; 0≤ai,di≤1000000\le a_i,d_i\le100000; 1≤li≤ri≤n1\le l_i\le r_i\le n; 1≤x≤y≤m1\le x\le y\le m.
  • Subtask 2 (30 points): 1≤n,m,k≤1000001\le n,m,k\le 100000; 0≤ai,di≤1000000\le a_i,d_i\le100000; 1≤li≤ri≤n1\le l_i\le r_i\le n; 1≤x≤y≤m1\le x\le y\le m; x=1,y=mx=1,y=m for every request.
  • Subtask 3 (50 points): 1≤n,m,k≤1000001\le n,m,k\le 100000; 0≤ai,di≤1000000\le a_i,d_i\le100000; 1≤li≤ri≤n1\le l_i\le r_i\le n; 1≤x≤y≤m1\le x\le y\le m.

Example 1

Input

3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3

Output

9 18 17

Explanation

The operations occur 2,3,2 times. Add [2,2,0], [6,6,6], [0,8,8] to the initial array.

Example 2

Input

1 1 1
1
1 1 1
1 1

Output

2

Explanation

The only operation adds 1 to the only element.

Example 3

Input

4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3

Output

5 18 31 20

Explanation

Operation counts are 4,6,4; element increases are 4,16,28,16.