Go | Prefix Sum Twice | O(n^2+m), O(n^2)
Approach\nCalculate prefix sum twice, one by row, the other by column.\n\n# Complexity\nm: The number of queries\n- Time complexity: O(n^2 + m)\n- Space complex
# Approach\nCalculate prefix sum twice, one by row, the other by column.\n\n# Complexity\n`m`: The number of `queries`\n- Time complexity: $$O(n^2 + m)$$\n- Space complexity: $$O(n^2)$$ for result\n\n# Code\n```golang []\n\nfunc rangeAddQueries(n int, queries [][]int) [][]int {\n\tres := make([][]int, n+1)\n\tfor i := range res {\n\t\tres[i] = make([]int, n+1)\n\t}\n\n\tvar rf, cf, rt, ct int\n\n\tfor _, q := range queries {\n\t\trf, cf, rt, ct = q[0], q[1], q[2], q[3]\n\t\tres[rf][cf] += 1\n\t\tres[rf][ct+1] -= 1\n\t\tres[rt+1][cf] -= 1\n\t\tres[rt+1][ct+1] += 1\n\t}\n\n\tfor r := 1; r < n; r++ {\n\t\tfor c := 0; c < n; c++ {\n\t\t\tres[r][c] += res[r-1][c]\n\t\t}\n\t}\n\n\tfor r := 0; r < n; r++ {\n\t\tfor c := 1; c < n; c++ {\n\t\t\tres[r][c] += res[r][c-1]\n\t\t}\n\t}\n\n\tfor r := 0; r < n; r++ {\n\t\tres[r] = res[r][:n]\n\t}\n\n\treturn res[:n]\n}\n\n\n```
['Go']