using
System;
class
GFG {
public
static
int
[, ] solveQueries(
int
N,
int
[, ] Queries)
{
int
[, ] matrix =
new
int
[N + 2, N + 2];
int
[, ] row =
new
int
[N + 2, N + 2];
int
[, ] col =
new
int
[N + 2, N + 2];
for
(
int
i = 0; i < Queries.GetLength(0); i++) {
int
a = Queries[i, 0];
int
b = Queries[i, 1];
int
c = Queries[i, 2];
int
d = Queries[i, 3];
row[a, b]++;
row--;
col[a, d + 1]--;
col++;
}
for
(
int
i = 0; i < N; i++) {
for
(
int
j = 1; j < N; j++) {
row[j, i] += row[j - 1, i];
col[j, i] += col[j - 1, i];
}
}
for
(
int
i = 0; i < N; i++) {
matrix[i, 0] = row[i, 0] + col[i, 0];
}
for
(
int
i = 1; i <= N; i++) {
for
(
int
j = 0; j < N; j++) {
matrix[j, i] += matrix[j, i - 1] + row[j, i]
+ col[j, i];
}
}
int
[, ] res =
new
int
[N, N];
for
(
int
i = 0; i < N; i++)
for
(
int
j = 0; j < N; j++)
res[i, j] = matrix[i, j];
return
res;
}
static
void
printAns(
int
[, ] res)
{
for
(
int
i = 0; i < res.GetLength(0); i++) {
for
(
int
j = 0; j < res.GetLength(1); j++) {
Console.Write(res[i, j] +
" "
);
}
Console.WriteLine();
}
}
public
static
void
Main()
{
int
N = 6;
int
q = 6;
int
[, ] Queries
= { { 4, 0, 5, 3 }, { 0, 0, 3, 4 },
{ 1, 2, 1, 2 }, { 1, 1, 2, 3 },
{ 0, 0, 3, 1 }, { 1, 0, 2, 4 } };
int
[, ] res = solveQueries(N, Queries);
printAns(res);
}
}