[Golang] Prefix Sum / Line Sweep
Code\n\nfunc rangeAddQueries(n int, queries [][]int) [][]int {\n  mat := make([][]int, n)\n  for i := 0; i < len(mat); i++ {\n    mat[i] = make([]int, n)\n  }\n
# Code\n```\nfunc rangeAddQueries(n int, queries [][]int) [][]int {\n  mat := make([][]int, n)\n  for i := 0; i < len(mat); i++ {\n    mat[i] = make([]int, n)\n  }\n  // Let\'s mark the start and one after the end and then do a prefix sum at the\n  // end. This is very much like line sweep.\n  for _, query := range queries {\n    rowStart, colStart := query[0], query[1]\n    rowEnd, colEnd := query[2], query[3]\n    for i := rowStart; i <= rowEnd; i++ {\n      mat[i][colStart]++\n      if colEnd+1 < n {\n        mat[i][colEnd+1]--\n      }\n    }\n  }\n  for i := 0; i < n; i++ {\n    for j := 1; j < n; j++ {\n      mat[i][j] = mat[i][j-1] + mat[i][j]\n    }\n  }\n  return mat\n}\n```
['Line Sweep', 'Prefix Sum', 'Go']