File tree Expand file tree Collapse file tree 5 files changed +16
-13
lines changed
Expand file tree Collapse file tree 5 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 11#pragma once
2+ // ! @code
3+ // ! bit.walk([&](int r, ll sum) -> bool {
4+ // ! // sum = a[0] + a[1] + ... + a[r - 1]
5+ // ! });
6+ // ! int r = bit.walk2(sum);
7+ // ! // Returns min r s.t. sum of [0,r] >= sum
8+ // ! // Returns n if sum of [0,n-1] < sum
9+ // ! @endcode
210// ! @time O(n + q log n)
311// ! @space O(n)
412// NOLINTNEXTLINE(readability-identifier-naming)
Original file line number Diff line number Diff line change 1- // ! Requires sum of [i,i] >= 0
2- // ! Returns min r s.t. sum of [0,r] >= sum
3- // ! Returns n if sum of [0,n-1] < sum
41int walk2 (ll sum) {
52 if (sum <= 0 ) return -1 ;
63 int r = 0 ;
Original file line number Diff line number Diff line change 1- // ! @code
2- // ! bit.walk([&](int r, ll sum) -> bool {
3- // ! // sum = a[0] + a[1] + ... + a[r - 1]
4- // ! });
5- // ! @endcode
61void walk (const auto & f) {
72 ll sum = 0 ;
83 for (int i = bit_floor (size (s)), r = 0 ; i; i /= 2 )
Original file line number Diff line number Diff line change 11#pragma once
2+ // ! @code
3+ // ! bit.walk([&](int r, ll sum) -> bool {
4+ // ! // sum = a[0] + a[1] + ... + a[r]
5+ // ! });
6+ // ! int r = bit.walk2(sum);
7+ // ! // Returns min r s.t. sum of [0,r] >= sum
8+ // ! // Returns n if sum of [0,n-1] < sum
9+ // ! @endcode
210// ! @time O(n + q log n)
311// ! @space O(n)
412// NOLINTNEXTLINE(readability-identifier-naming)
Original file line number Diff line number Diff line change 1- // ! @code
2- // ! bit.walk([&](int r, ll sum) -> bool {
3- // ! // sum = a[0] + a[1] + ... + a[r]
4- // ! });
5- // ! @endcode
61void walk (const auto & f) {
72 ll sum = 0 ;
83 for (int i = bit_floor (size (s)), r = 0 ; i; i /= 2 )
You can’t perform that action at this time.
0 commit comments