Skip to content

Commit e989b76

Browse files
upd
1 parent 83850e7 commit e989b76

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

solutions/gold/cses-1148.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ id: cses-1148
33
source: CSES
44
title: Maximum Building II
55
author: Mihnea Brebenel
6-
prerequisites:
7-
- prefix-sums
86
---
97

108
## Explanation
@@ -16,7 +14,7 @@ Similarly to [Maximum Building I](https://cses.fi/problemset/task/1147) apply mo
1614

1715
Using [prefix sums](/silver/more-prefix-sums#2d-prefix-sums) and [difference arrays](https://codeforces.com/blog/entry/78762)
1816
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+
and the lowerbound of the rectangle of width $r_{i,j}$ i.e. how much it can expand above and below line $i$ maintaing width $r_{i, j}$.
2018
We'll do difference arrays on each column independently. Accordingly, the updates of the answer matrix look like this:
2119
- $ans[1][r_{i,j}]++$
2220
- $ans[i - u_{i, j} + 2][r_{i,j}]--$ , the upperbound
@@ -58,6 +56,7 @@ int main() {
5856
}
5957
}
6058
stack<int> st;
59+
// Precompute u[i][j] and d[i][j]
6160
for (int j = 1; j <= m; j++) {
6261
while (!st.empty()) { st.pop(); }
6362
for (int i = 1; i <= n; i++) {
@@ -72,6 +71,7 @@ int main() {
7271
st.push(i);
7372
}
7473
}
74+
// Make difference array on each column independently
7575
for (int i = 1; i <= n; i++) {
7676
for (int j = 1; j <= m; j++) {
7777
ans[1][r[i][j]]++;

0 commit comments

Comments
 (0)