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

#PS0000272. Cập nhật hình hộp bằng sai phân 3D (3D Cuboid Updates)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cập nhật hình hộp bằng sai phân 3D (3D Cuboid Updates)

3D Cuboid Updates

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

An nx×ny×nzn_x\times n_y\times n_z array is initially zero, with 1-based indices. Each operation adds integer vv to every cell (x,y,z)(x,y,z) with x1≤x≤x2x_1\le x\le x_2, y1≤y≤y2y_1\le y\le y_2, z1≤z≤z2z_1\le z\le z_2. Print the final array.

Input

First line: nx,ny,nz,qn_x,n_y,n_z,q. Next qq lines: x1,y1,z1,x2,y2,z2,vx_1,y_1,z_1,x_2,y_2,z_2,v.

Output

Print nxnynzn_xn_yn_z integers on one line, in increasing xx, then increasing yy, then increasing zz.

Subtasks

  • Subtask 1 (20 points): 1≤nx,ny,nz≤51\le n_x,n_y,n_z\le 5; 1≤q≤2000001\le q\le 200000; 1≤x1≤x2≤nx1\le x_1\le x_2\le n_x; 1≤y1≤y2≤ny1\le y_1\le y_2\le n_y; 1≤z1≤z2≤nz1\le z_1\le z_2\le n_z; ∣v∣≤106|v|\le10^6.
  • Subtask 2 (30 points): 1≤nx,ny,nz≤601\le n_x,n_y,n_z\le 60; 1≤q≤1001\le q\le 100; 1≤x1≤x2≤nx1\le x_1\le x_2\le n_x; 1≤y1≤y2≤ny1\le y_1\le y_2\le n_y; 1≤z1≤z2≤nz1\le z_1\le z_2\le n_z; ∣v∣≤106|v|\le10^6.
  • Subtask 3 (50 points): 1≤nx,ny,nz≤601\le n_x,n_y,n_z\le 60; 1≤q≤2000001\le q\le 200000; 1≤x1≤x2≤nx1\le x_1\le x_2\le n_x; 1≤y1≤y2≤ny1\le y_1\le y_2\le n_y; 1≤z1≤z2≤nz1\le z_1\le z_2\le n_z; ∣v∣≤106|v|\le10^6.

Example 1

Input

1 1 2 1
1 1 1 1 1 2 3

Output

3 3

Explanation

Both cells receive 3.

Example 2

Input

2 1 2 2
1 1 1 2 1 2 5
2 1 2 2 1 2 -7

Output

5 5 5 -2

Explanation

First add 5 to all four cells, then subtract 7 only at (2,1,2)(2,1,2), giving -2 there.