commit ae5a9173125eb2af2d51eed32e401600aa070da6
parent ca75407896b7dde4a0edd1d11c575cd6b699b96e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 8 Aug 2024 19:32:49 +0200
1 Random Problem
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Problems/2536.cpp b/Problems/2536.cpp
@@ -0,0 +1,27 @@
+class Solution {
+ public:
+ vector<vector<int>> rangeAddQueries(int n, const vector<vector<int>> &queries) const {
+ vector<vector<int>> mat(n, vector(n, 0));
+
+ for (const auto &query : queries) {
+ mat[query[0]][query[1]]++;
+ if (query[2] + 1 < n && query[3] + 1 < n) mat[query[2] + 1][query[3] + 1]++;
+ if (query[2] + 1 < n) mat[query[2] + 1][query[1]]--;
+ if (query[3] + 1 < n) mat[query[0]][query[3] + 1]--;
+ }
+
+ for (int i = 0; i < n; i++) {
+ for (int j = 0, acc = 0; j < n; j++) {
+ mat[i][j] = acc += mat[i][j];
+ }
+ }
+
+ for (int j = 0; j < n; j++) {
+ for (int i = 0, acc = 0; i < n; i++) {
+ mat[i][j] = acc += mat[i][j];
+ }
+ }
+
+ return mat;
+ }
+};
diff --git a/README.md b/README.md
@@ -1203,6 +1203,7 @@ for solving problems.
| 2498 | Medium | [Frog Jump II](Problems/2498.cpp) |
| 2517 | Medium | [Maximum Tastiness of Candy Basket](Problems/2517.cpp) |
| 2527 | Medium | [Find Xor-Beauty of Array](Problems/2527.cpp) |
+| 2536 | Medium | [Increment Submatrices by One](Problems/2536.cpp) |
| 2537 | Medium | [Count the Number of Good Subarrays](Problems/2537.cpp) |
| 2540 | Easy | [Minimum Common Value](Problems/2540.cpp) |
| 2542 | Medium | [Maximum Subsequence Score](Problems/2542.cpp) |