Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

MARBLEGF - Editorial

$
0
0

PROBLEM LINK

Contest

AUTHOR

@kuruma

TESTER

@white_king

SOLUTION

This is a trivial application of Fenwick tree. Those not familiar with Fenwick tree may look at the topcoder editorial available here.

All this is asking you to do is to online update of a single element in the array and the sum in a range. Note that the sum of elements of an array from indices i through j can be written as cum_sum[j]-cum_sum[i] where cum_sum[i] is the cumulative sum of all elements in 1 through i.

Seeking the cumulative sum at any point in an array after multiple updates can be done efficiently in O(log n) using the Fenwick tree. You may use the update and read function (available here) in order to do this efficiently.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>