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

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

Hi,

I am trying to implement a 2-D segment tree, seg with N = 100000... The catch is that I only need to get the query answer for Q(100000) nodes say query(i,j) : denoting the value in seg[i][j]... but i need to online (lazily) update the seg tree, seg[lx...rx][ly...ry].

Can anyone help me with this problem?

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

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

Auto comment: topic has been updated by zeref_dragoneel (previous revision, new revision, compare).

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

What is the problem with using a dynamic 2D segment tree?

Another way which is much easier and faster is using 2D compressed Fenwick tree but it will be offline.

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

    http://www.spoj.com/problems/XXXXXXXX/

    Did not get to any solution other than dynamic 2D segment tree with range updates.

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

      Well in this problem you don't need an online solution. As I said you can use 2D compressed Fenwick tree. You also can replace the inner dynamic segment tree in your solution with a compressed Fenwick or Treap. In such a way you could make the solution faster and make it use less memory. If you didn't get what I meant by compressed Fenwick, here is an implementation. If you didn't get what I meant by "replacing the inner segment tree" you can take a look at my solution to this problem (solution). I used a similar approach. It won't be hard to figure out how to reapply the same approach to the problem you've linked.

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

        Can you please elaborate on "given L, R, find the sum of a[i] for L ≤ i ≤ R such that left[i] < L. This can be done with range query in any 2D data structure."?

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

          On one dimension you have the indexes in the array and on the other one you also have the indexes in the array. Then the query becomes:

          Find sum in sub-rectangle with upper left point (L, 0) and lower right point (R, L). And when we do update we update point (i, left[i]) with value a[i].

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

            Just so that I understood it correctly, is this similar to a segment tree where each node is a treap so node (l,r) gives the treap for present indices in [0, r].

            except you are having a compressed fenwick tree instead of a treap.

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

              Exactly. That's why I mentioned that it also can be done with treap, but unfortunately I think it will not be fast enough.