2536. 子矩阵元素加1
class Solution {
public:
vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {
vector<vector<int>> dif(n + 5,vector<int>(n + 5,0));
for(int i = 0;i < queries.size();i ++)
{
int x1 = queries[i][0] + 1,y1 = queries[i][1] + 1,x2 = queries[i][2] + 1,y2 = queries[i][3] + 1;
dif[x1][y1] ++;
dif[x2 + 1][y2 + 1] ++;
dif[x2 + 1][y1] --;
dif[x1][y2 + 1] --;
}
vector<vector<int>> ans(n);
for(int i = 1;i <= n;i ++)
{
for(int j = 1;j <= n;j ++)
{
dif[i][j] += dif[i - 1][j] + dif[i][j - 1] - dif[i - 1][j - 1];
ans[i - 1].push_back(dif[i][j]);
}
}
return ans;
}
};
标签:int,dif,元素,矩阵,vector,queries,x2,y2,2536
From: https://www.cnblogs.com/chhh31/p/18560293