DAY 2

3.5

65 votes
Problem

You are given a N x N matrix and have to perform Q queries on it. Queries are of 2 types:
a) 1 a b c : For each element eij (a<=i<=b and 1<=j<=N) in the matrix, eij=eijc
b) 2 a b c : For each element eij (1<=i<=N and a<=j<=b) in the matrix, eij=eijc

After these queries are performed, print the sum of the diagonal (top left to bottom right) elements.

INPUT
The first line contains an integer denoting N
The next N lines contains N space separated integers
The next line contains an integer denoting Q
The next Q lines contain 4 space separated integers depending on the type of query

OUTPUT
A single line denoting the sum of diagonal elements of the final matrix

CONSTRAINTS
1<=N<=1000
1<=Q<=2106
1<=c<=103
1<=a,b<=N
1<=eij<=104

NOTE: Use fast I/O.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?