Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- signed main() {
- struct Node {
- int max = -1e18;
- int l = -1, r = -1;
- };
- vector<Node> tree(1);
- auto assert_left = [&] (int u) -> void {
- if (tree[u].l == -1) {
- tree.push_back({});
- tree[u].l = tree.size()-1;
- }
- };
- auto assert_right = [&] (int u) -> void {
- if (tree[u].r == -1) {
- tree.push_back({});
- tree[u].r = tree.size()-1;
- }
- };
- auto get_max = [&] (auto f, int u, int tl, int tr, int l, int r) -> int {
- if (tl == l && tr == r) {
- return tree[u].max;
- }
- int tm = (tl + tr) >> 1;
- int ret = -1e18;
- if (l <= tm) {
- assert_left(u);
- ret = max(ret, f(f, tree[u].l, tl, tm, l, min(tm, r)));
- }
- if (r >= tm+1) {
- assert_right(u);
- ret = max(ret, f(f, tree[u].r, tm+1, tr, max(l, tm+1), r));
- }
- return ret;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement