@@ -14,9 +14,9 @@ Similarly to [Maximum Building I](https://cses.fi/problemset/task/1147) apply mo
14
14
- $u_{i, j}$ , the last line above $i$ with cell $(x, j)$ such that $r_{x, j} > r_{i, j}$
15
15
- $d_{i, j}$ , the last line under $i$ with cell $(y, j)$ such that $r_{y, j} \ge r_{i, j}$
16
16
17
- Using [prefix sums](/silver/more-prefix-sums#2d-prefix-sums) and [difference arrays](https://codeforces.com/blog/entry/78762)
18
- we can efficiently update the answer matrix. Having $r_{i,j}$, $u_{i,j}$ and $d_{i,j}$ precomputed, we know the upperbound
19
- and the lowerbound of the rectangle of of width $r_{i,j}$ i.e. how much it can expand above and below line $i$ maintaing width $r_{i, j}$.
17
+ Using [prefix sums](/silver/more-prefix-sums#2d-prefix-sums) and [difference arrays](https://codeforces.com/blog/entry/78762)
18
+ we can efficiently update the answer matrix. Having $r_{i,j}$, $u_{i,j}$ and $d_{i,j}$ precomputed, we know the upperbound
19
+ and the lowerbound of the rectangle of of width $r_{i,j}$ i.e. how much it can expand above and below line $i$ maintaing width $r_{i, j}$.
20
20
We'll do difference arrays on each column independently. Accordingly, the updates of the answer matrix look like this:
21
21
- $ans[1][r_{i,j}]++$
22
22
- $ans[i - u_{i, j} + 2][r_{i,j}]--$ , the upperbound
@@ -39,7 +39,7 @@ Finally, add $ans[i][j]$ to $ans[i][j-1]$ i.e. a submatrix of size $i \times j$
39
39
40
40
using namespace std;
41
41
42
- int main() {
42
+ int main() {
43
43
int n, m;
44
44
cin >> n >> m;
45
45
vector<vector<int>> r(n + 2, vector<int>(m + 2));
@@ -106,4 +106,4 @@ int main() {
106
106
```
107
107
108
108
</CPPSection>
109
- </LanguageSection>
109
+ </LanguageSection>
0 commit comments