Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. const int MAX_N = (int)1e5 + 77;
  2. const int INT_INF = (int)2e9;
  3.  
  4. int tree[2 * MAX_N], a[MAX_N];
  5.  
  6. inline void build()
  7. {
  8.     for(int i = 0; i < n; ++i)
  9.         tree[i + n] = a[i];
  10.  
  11.     for(int i = n - 1; i > 0; --i)
  12.         tree[i] = min(tree[2 * i], tree[2 * i + 1]);
  13. }
  14.  
  15. inline void ch(int i, int x)
  16. {
  17.     i += n;
  18.     tree[i] = x;
  19.  
  20.     while(i != 1)
  21.     {
  22.         i /= 2;
  23.         tree[i] = min(tree[2 * i], tree[2 * i + 1]);
  24.     }
  25. }
  26.  
  27. inline int get(int l, int r)
  28. {
  29.     int acc = LL_INF;
  30.     l += n, r += n + 1;
  31.  
  32.     while(l != r)
  33.     {
  34.         if(l & 1)
  35.             acc = min(acc, tree[l++]);
  36.  
  37.         if(r & 1)
  38.             acc = min(acc, tree[--r]);
  39.  
  40.         l /= 2, r /= 2;
  41.     }
  42.  
  43.     return acc;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement