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

#PS0000265. Tăng các ma trận con thêm một (Increment Submatrices by One)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tăng các ma trận con thêm một (Increment Submatrices by One)

Increment Submatrices by One

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An initially zero N×NN\times N matrix uses zero-based row and column indices. Each operation (r1,c1,r2,c2)(r_1,c_1,r_2,c_2) adds one to every cell of the inclusive rectangle with these opposite corners. Print the matrix after all QQ operations.

Input

First line: N,QN,Q. Next QQ lines: r1,c1,r2,c2r_1,c_1,r_2,c_2.

Output

Print NN lines of NN space-separated integers.

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le 12; 1≤Q≤301\le Q\le 30; 0≤r1≤r2<N0\le r_1\le r_2<N; 0≤c1≤c2<N0\le c_1\le c_2<N.
  • Subtask 2 (30 points): 1≤N≤5001\le N\le 500; 1≤Q≤100001\le Q\le 10000; 0≤r1≤r2<N0\le r_1\le r_2<N; 0≤c1≤c2<N0\le c_1\le c_2<N; r1=r2r_1=r_2.
  • Subtask 3 (50 points): 1≤N≤5001\le N\le 500; 1≤Q≤100001\le Q\le 10000; 0≤r1≤r2<N0\le r_1\le r_2<N; 0≤c1≤c2<N0\le c_1\le c_2<N.

Example 1

Input

3 2
1 1 2 2
0 0 1 1

Output

1 1 0
1 2 1
0 1 1

Explanation

Cell (1,1) is covered twice; other cells at most once.

Example 2

Input

2 1
0 0 1 1

Output

1 1
1 1

Explanation

One operation covers the entire matrix.