Блог пользователя nikizakr

Автор nikizakr, история, 7 лет назад, По-английски

Hi Codeforces :D I'm looking for some problems about 3D prefix sum can you provide some links thanks a lot

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 4   Проголосовать: нравится +3 Проголосовать: не нравится

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:

Code
  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    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 wrote S[i][j+1] instead of S[i-1][j].

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Here's a task from UVa online judge 10755 — Garbage Heap.

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

one from atcoder: cuboid sum query