Advertisement
askarulytarlan

Untitled

Mar 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1.  
  2. 1
  3. 2 3
  4. 4 5 6 7
  5. 8 9 10 11 12 13 14 15
  6. 1 2 3 4 5
  7.  
  8.  
  9. n
  10. a1 a2 a3 ... an
  11. m
  12. l1 r1
  13. l2 r2
  14. .
  15. .
  16. .
  17. ln rn
  18.  
  19.  
  20. #include <iostream>
  21.  
  22. using namespace std;
  23.  
  24. void build(int v, int L, int R) {
  25. if (L == R) {
  26. t[v] = a[L];
  27. return;
  28. }
  29. int mid = (L + R) / 2;
  30. build(v * 2, L, mid);
  31. build(v * 2 + 1, mid + 1, R);
  32. t[v] = max(t[v * 2], t[v * 2 + 1]);
  33. }
  34.  
  35. int main() {
  36.  
  37. cin >> n;
  38.  
  39. for (int i = 1; i <= n; i++)
  40. cin >> a[i];
  41.  
  42. build(1, 1, n);
  43.  
  44.  
  45. 1) sum
  46. 2) min
  47. дерево снизу и сверху
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement