File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed
library/data_structures_[l,r]/seg_tree_uncommon
tests/library_checker_aizu_tests/data_structures Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 11int walk (int l, int r, const auto & f) {
2- while (l <= r) {
3- int u = l + n, v = __lg (min (u & -u, r - l + 1 ));
4- if (f (s[u >> v])) l += 1 << v;
5- else r = l + (1 << v) - 2 ;
6- }
7- return l;
2+ l += n, r += n;
3+ if (T x = s[l]; f (x))
4+ for (l++; l <= r;) {
5+ int v = __lg (min (l & -l, r - l + 1 ));
6+ if (T y = op (x, s[l >> v]); f (y)) l += 1 << v, x = y;
7+ else r = l + (1 << v) - 2 ;
8+ }
9+ return l - n;
810}
Original file line number Diff line number Diff line change 11#define PROBLEM \
22 " https://judge.yosupo.jp/problem/predecessor_problem"
33#include " ../template.hpp"
4+ int __lg (unsigned x) {
5+ return bit_width (x) - 1 ;
6+ }
47#include " ../../../library/data_structures_[l,r]/seg_tree.hpp"
58int main () {
69 cin.tie (0 )->sync_with_stdio (0 );
@@ -32,13 +35,8 @@ int main() {
3235 if (total == 0 ) {
3336 cout << -1 << ' \n ' ;
3437 } else {
35- int pref_sum = 0 ;
3638 cout << st.walk (0 , k, [&](int sum) {
37- if (pref_sum + sum < total) {
38- pref_sum += sum;
39- return 1 ;
40- }
41- return 0 ;
39+ return sum < total;
4240 }) << ' \n ' ;
4341 }
4442 }
You can’t perform that action at this time.
0 commit comments