Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int MAX_N = (int)1e5 + 77;
- const int INT_INF = (int)2e9;
- int tree[2 * MAX_N], a[MAX_N];
- inline void build()
- {
- for(int i = 0; i < n; ++i)
- tree[i + n] = a[i];
- for(int i = n - 1; i > 0; --i)
- tree[i] = min(tree[2 * i], tree[2 * i + 1]);
- }
- inline void ch(int i, int x)
- {
- i += n;
- tree[i] = x;
- while(i != 1)
- {
- i /= 2;
- tree[i] = min(tree[2 * i], tree[2 * i + 1]);
- }
- }
- inline int get(int l, int r)
- {
- int acc = LL_INF;
- l += n, r += n + 1;
- while(l != r)
- {
- if(l & 1)
- acc = min(acc, tree[l++]);
- if(r & 1)
- acc = min(acc, tree[--r]);
- l /= 2, r /= 2;
- }
- return acc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement