Hi Codeforces :D I'm looking for some problems about 3D prefix sum can you provide some links thanks a lot
# | User | Rating |
---|---|---|
1 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 161 |
4 | Um_nik | 160 |
5 | atcoder_official | 159 |
6 | djm03178 | 157 |
7 | adamant | 153 |
8 | luogu_official | 150 |
9 | awoo | 149 |
10 | TheScrasse | 146 |
Hi Codeforces :D I'm looking for some problems about 3D prefix sum can you provide some links thanks a lot
Name |
---|
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.
one from atcoder: cuboid sum query