Advertisement
Augenbrauen

drzewo przedziałowe nr 3

Dec 11th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.                      
  4. using namespace std;
  5.  
  6. int suma;
  7.  
  8. struct Tree
  9. {
  10.    int sz = 1;
  11.     vector<int> t;
  12.     Tree(int n)
  13.     {
  14.         while (sz < n)
  15.             sz *= 2;
  16.         t.resize(sz * 2);                  
  17.     }
  18.     int zwsuma (int l, int r)
  19.     {
  20.         l += sz;
  21.         r += sz;
  22.         suma = t[l] + t[r];
  23.         while (l / 2 != r / 2)
  24.         {
  25.             if (l % 2 == 0)
  26.                 suma += + t[l + 1];                
  27.             if (r % 2 == 1)
  28.                 suma += t[r - 1];
  29.             l /= 2;              
  30.             r /= 2;          
  31.         }
  32.         return suma;      
  33.     }
  34.    
  35.     void zmien (int v, int z) // zmień jedną liczbę
  36.     {
  37.         v += sz;
  38.         t[v] = z;
  39.         while (v > 0)
  40.         {
  41.             v /= 2;            
  42.             t[v] = t[v / 2] + t[v / 2 + 1];
  43.         }
  44.  
  45.     }
  46. };
  47.  
  48. int main()
  49. {
  50.     // ios_base::sync_with_stdio(0);
  51.     // cin.tie(0);
  52.  
  53.  
  54.  
  55.    
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement