Advertisement
999ms

Untitled

Mar 14th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. struct Node{
  6.     Node * l, * r;
  7.     int value;
  8. };
  9.  
  10. vector<Node *> versions;
  11.  
  12.  
  13. Node * newNode(){
  14.     Node * kek = new Node();
  15.     return kek;
  16. }
  17.  
  18. Node * Build(int v, int tl, int tr, vector<int> & a){
  19.     if(tl == tr){
  20.         auto leave  = newNode();
  21.         leave->l = NULL;
  22.         leave->r = NULL;
  23.         leave->value = a[tl];
  24.         return leave;
  25.     } else {
  26.         int tm = (tl + tr)/2;  
  27.         auto L = Build(v, tl, tm, a);
  28.         auto R = Build(v, tm+1, tr, a);
  29.         auto V = newNode();
  30.         V->l = L;
  31.         V->r = R;
  32.         V->value = max(L->value,R->value);
  33.         return V;
  34.     }
  35. }
  36.  
  37.  
  38. int get(Node * v, int tl, int tr, int l, int r){
  39.     if(l > r) return 0;
  40.     if(l == tl  && r == tr){
  41.         return v->value;
  42.     } else {
  43.         int tm = (tl + tr) / 2;
  44.         int lAns = get(v->l, tl, tm, l, min(r, tm));
  45.         int rAns = get(v->r, tm+1,tr, max(tm+1,l),r);
  46.         return max(rAns,lAns);
  47.     }
  48. }
  49.  
  50. Node * upd(Node * v, int tl, int tr, int i, int value){
  51.     if(tl == tr){
  52.         auto curV = newNode();
  53.         curV->l = NULL;
  54.         curV->r = NULL;
  55.         curV->value = value;
  56.         return curV;
  57.     } else {
  58.         int tm = (tl + tr) / 2;
  59.         if(i <= tm){
  60.             auto lUpd = upd(v->l, tl, tm, i, value);   
  61.             auto curV = newNode();
  62.             curV->r = v -> r;
  63.             curV->l = lUpd;
  64.             curV->value = max(lUpd->value, v->r->value);       
  65.             return curV;
  66.         } else {
  67.             auto rUpd = upd(v->r, tm+1,tr, i, value);
  68.             auto curV = newNode();
  69.             curV->r = rUpd;
  70.             curV->l = v->l;
  71.             curV->value = max(v->l->value, rUpd->value);
  72.             return curV;
  73.         }
  74.     }
  75. }
  76.  
  77.  
  78. int main(){
  79.   ios_base::sync_with_stdio(false);
  80.   cin.tie(nullptr);
  81.    
  82.   return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement