 => Int -> a -> BIT a -> BIT a
inc' i w b =
  BIT n $ V.create $ do
    mv <- V.thaw v
    forM_ xs $ M.modify mv (<>w)
    return mv
  where
    (n, v) = (getN b, vec b)
    xs = takeWhile (<=n) . iterate (\x -> x + x .&. (-x)) $ i


{- |
lookup the sum of all values from index 1 to index i. O(log n)
-}
(!) :: Monoid a
inc' :: Monoid a => Int -> a -> BIT a -> BIT a
inc' i w b =
  BIT n $ V.create $ do
    mv <- V.thaw v
    forM_ xs $ M.modify mv (<>w)
    return mv
  where
    (n, v) = (getN b, vec b)
    xs = takeWhile (<=n) . iterate (\x -> x + x .&. (-x)) $ i


{- |
lookup the sum of all values from index 1 to index i. O(log n)
-}
inc' i w b =
  BIT n $ V.create $ do
    mv <- V.thaw v
    forM_ xs $ M.modify mv (<>w)
    return mv
  where
    (n, v) = (getN b, vec b)
    xs = takeWhile (<=n) . iterate (\x -> x + x .&. (-x)) $ i


{- |
lookup the sum of all values from index 1 to index i. O(log n)
-}