✅C++ || Scanline Algo || CLEAN CODE
\n\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tvector> rangeAddQueries(int n, vector>& queries) {\n\t\t\t   vector> mat(n, vector(n)), diff(n + 1, vector(n + 1));
![image](https://assets.leetcode.com/users/images/35be67d7-2dd9-404a-8c06-c2c5112ef9dc_1673757401.114663.png)\n\n\n\tclass Solution {\n\t\tpublic:\n\t\t\tvector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n\t\t\t   vector<vector<int>> mat(n, vector<int>(n)), diff(n + 1, vector<int>(n + 1));\n\n\t\t\tfor (auto q : queries) {\n\t\t\t\tint row1 = q[0], col1 = q[1], row2 = q[2], col2 = q[3];\n\t\t\t\tdiff[row1][col1]++;\n\t\t\t\tdiff[row1][col2 + 1]--;\n\t\t\t\tdiff[row2 + 1][col1]--;\n\t\t\t\tdiff[row2 + 1][col2 + 1]++;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tmat[i][j] += diff[i][j];\n\t\t\t\t\tif (i > 0) mat[i][j] += mat[i - 1][j];\n\t\t\t\t\tif (j > 0) mat[i][j] += mat[i][j - 1];\n\t\t\t\t\tif (i > 0 && j > 0) mat[i][j] -= mat[i - 1][j - 1];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mat;\n\t\t\t}\n\t\t};
['C', 'C++']