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

Автор Duelist1234, история, 2 года назад, По-английски

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.

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

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

What about BIT?

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

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