Tap here to switch tabs
Problem
Submissions

Problem: Sum of Matrix After Queries

Try to solve the Sum of Matrix After Queries problem.

Statement

You are given an integer n and a 22D integer array queries where each query is represented as queries[i] = [type_i, index_i, val_i].

Initially, there is a matrix of size n $ imes$ n with all elements set to 00.

For each query:

  • If type_i =0= 0, set every element in row index_i to val_i, overwriting any existing values.

  • If type_i =1= 1, set every element in column index_i to val_i, overwriting any existing values.

Return the total sum of all elements in the matrix after processing all queries.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • 1≤1 \leq queries.length ≤5imes104\leq 5 imes 10^4

  • queries[i].length =3= 3

  • 0≤0 \leq type_i ≤1\leq 1

  • 0≤0 \leq index_i << n

  • 0≤0 \leq val_i ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Matrix After Queries

Try to solve the Sum of Matrix After Queries problem.

Statement

You are given an integer n and a 22D integer array queries where each query is represented as queries[i] = [type_i, index_i, val_i].

Initially, there is a matrix of size n $ imes$ n with all elements set to 00.

For each query:

  • If type_i =0= 0, set every element in row index_i to val_i, overwriting any existing values.

  • If type_i =1= 1, set every element in column index_i to val_i, overwriting any existing values.

Return the total sum of all elements in the matrix after processing all queries.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • 1≤1 \leq queries.length ≤5imes104\leq 5 imes 10^4

  • queries[i].length =3= 3

  • 0≤0 \leq type_i ≤1\leq 1

  • 0≤0 \leq index_i << n

  • 0≤0 \leq val_i ≤105\leq 10^5