Created
August 23, 2020 15:57
-
-
Save musou1500/9dfa655da00bff933d950de18de1c3e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<vector<int>> Dim2PartialSum(vector<vector<int>> &mat, int w, int h) { | |
vector<vector<int>> psum(h + 1, vector<int>(w + 1, 0)); | |
for (int i = 0; i < h; ++i) { | |
for (int j = 0; j < w; ++j) { | |
psum[i + 1][j + 1] = | |
psum[i + 1][j] + psum[i][j + 1] + mat[i][j] - psum[i][j]; | |
} | |
} | |
return psum; | |
} | |
int Dim2PartialSumArea(vector<vector<int>> &psum, int x, int y, int w, int h) { | |
return psum[y + h][x + w] - psum[y + h][x] - psum[y][x + w] + psum[y][x]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment