Duelist1234's blog

By Duelist1234, history, 2 years ago, In English

So the problem is as following: You are given two integers n and q , and there is an array length n with all zeroes. There are q operations of 3 types: -output the sum in array a from i to j; -a[i] becomes 1; -a[i] becomes 0.

I know this can be done using segment trees but I think that is complicating it.

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

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What about BIT?

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As already writted, you can use Fenwick tree(binary indexed tree), it's very quick to implement, but not so easy to understand. If you want to know easy to understand solution with at least decent time complexity, you can look into the sqrt decomposition