Hi Codeforces :D I'm looking for some problems about 3D prefix sum can you provide some links thanks a lot
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | orzdevinwang | 3570 |
4 | Geothermal | 3569 |
4 | cnnfls_csy | 3569 |
6 | tourist | 3565 |
7 | maroonrk | 3531 |
8 | Radewoosh | 3521 |
9 | Um_nik | 3482 |
10 | jiangly | 3468 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Hi Codeforces :D I'm looking for some problems about 3D prefix sum can you provide some links thanks a lot
Название |
---|
After writing this comment I realized that your post was asking about problems rather than requesting a tutorial :). I hope someone will find this useful anyway.
Well, I think I could explain it right there. So, for 1D prefix sums you simply do
S[i + 1] = S[i] + a[i]
, nothing special here. For 2D, on the other side, you have to subtract overlapping region:S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + a[i][j]
. For 3D there will be even more overlapping:S[i][j][k] = S[i - 1][j][k] + S[i][j - 1][k] + S[i][j][k - 1] - S[i - 1][j - 1][k] - S[i][j - 1][k - 1] - S[i - 1][j][k - 1] + S[i - 1][j - 1][k - 1] + a[i][j][k]
. You can find similarity with inclusion-exclusion formulas. So, with adding new dimensions it becomes more burdensome exponentially. You can check out this code:The formula for two dimensions is wrong. I think it's a typo.
The correct formula is
S[i][j] = S[i][j-1] + S[i-1][j] - S[i-1][j-1] + A[i][j]
. You wroteS[i][j+1]
instead ofS[i-1][j]
.Thanks, corrected that.
Here's a task from UVa online judge 10755 — Garbage Heap.