How do I efficiently multiply a range of values of an array with a given number?

后端 未结 4 2005
孤城傲影
孤城傲影 2021-02-06 18:49

The naive way would be to linearly iterate the range and multiply with each number in the range.

Example: Array: {1,2,3,4,5,6,7,8,9,10}; Multiply index 3 to index 8 wit

4条回答
  •  感动是毒
    2021-02-06 19:49

    By BIT you can also update a range.(Range update by BIT).

    You can also use Segment Tree, RMQ. You can multiply with a given number easily.

    Nice tutorial about ST and RMQ. RMQ Topcoder and Segment Tree

提交回复
热议问题