Advertisement
prog3r

Untitled

Mar 3rd, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. signed main() {
  5. struct Node {
  6. int max = -1e18;
  7. int l = -1, r = -1;
  8. };
  9. vector<Node> tree(1);
  10. auto assert_left = [&] (int u) -> void {
  11. if (tree[u].l == -1) {
  12. tree.push_back({});
  13. tree[u].l = tree.size()-1;
  14. }
  15. };
  16. auto assert_right = [&] (int u) -> void {
  17. if (tree[u].r == -1) {
  18. tree.push_back({});
  19. tree[u].r = tree.size()-1;
  20. }
  21. };
  22. auto get_max = [&] (auto f, int u, int tl, int tr, int l, int r) -> int {
  23. if (tl == l && tr == r) {
  24. return tree[u].max;
  25. }
  26. int tm = (tl + tr) >> 1;
  27. int ret = -1e18;
  28. if (l <= tm) {
  29. assert_left(u);
  30. ret = max(ret, f(f, tree[u].l, tl, tm, l, min(tm, r)));
  31. }
  32. if (r >= tm+1) {
  33. assert_right(u);
  34. ret = max(ret, f(f, tree[u].r, tm+1, tr, max(l, tm+1), r));
  35. }
  36. return ret;
  37. };
  38.  
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement