usureluflorianr's blog

By usureluflorianr, history, 13 months ago, In English,

Hey guys, can you please give me some sources with easy BIT 2D implementation? I would be grateful also for some problems using this from easy to hard. Thanks in advance!

 
 
 
 
  • Vote: I like it  
  • +6
  • Vote: I do not like it  

»
13 months ago, # |
  Vote: I like it +21 Vote: I do not like it
  • »
    »
    13 months ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Thanks!

  • »
    »
    13 months ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    I know another one problem that can be solved using 3D BIT (100246B - B), but its statement only available in russian. But i can try to translate it.

    You are given a cube (coordinates of points in a cube is 0-indexed) with a side n (1 ≤ n ≤ 128) and 2 types of queries. Each query starts with its type (1 or 2). Type 1 is followed by 4 integers x, y, z, k (x, y, z — coordinates, k ( - 2·104 ≤ k ≤ 2·104) — the number of appeared/lost stars in this point (i don't know that i wrote it understandable) (i.e. that query means such operation: cube[x][y][z] +  = k). Type 2 query is followed by 6 integers x1, y1, z1, x2, y2, z2 — coordinates of subcube, you have to count number of stars in it (i.e. for x in[x1; x2]: for y in[y1; y2]: for z in[z1; z2]: res +  = cube[x][y][z]).

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      So, in conclusion, no matter how many dimensions we have, always we can apply BIT (if the statement ask for it)

      • »
        »
        »
        »
        4 weeks ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        I think for higher dimensions, it is best to think of it as the number of points enclosed in the n-dimensional structure.... Like in 1D the BIT is used to calculate the prefix sum ... it is in a way looking back from current point up until origin and calculating some type of summation, extend this to n-dimensions and you will agree with my first statement.

  • »
    »
    6 months ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    I was reading 2D BIT, gfg implementation https://www.geeksforgeeks.org/two-dimensional-binary-indexed-tree-or-fenwick-tree/

    Please help me with some doubts, In the updateBit and getSum function inner "y" loop is not initialized again. Is it a mistake or is it meant to be that way?

    If it is meant to be that way can you explain how is it working and what is the need of outer loop as the same work can be done with the help of an "if" statement.

    Thanks in advance..

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      That's probably a mistake, since I've tried it and it got WA. I always use 2D fenwick initializing the nested variable.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    here is another problem that can be solved using 2D BIT: https://codeforces.com/contest/1093/problem/E

»
12 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Hello, i use the implementation of BIT 2D present in this notebook. I hope helps! :) Sorry the codes are in english, but the comments are in portuguese.

https://github.com/Gabriel123Duarte/maratona-final/blob/master/Notebook/100%5Eo.pdf