Advertisement
askarulytarlan

дерево сумм снизу

Apr 8th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, a[100500], inf = -1000000000, t[500500];
  4. int main(){
  5. freopen("C.in", "r", stdin);
  6. freopen("C.out", "w", stdout);
  7. cin >> n;
  8. for(int i = 1; i <= n; u++){
  9. cin >> a[i];
  10. }
  11. sz = 1;
  12. while(sz < n){
  13. sz *= 2;
  14. }
  15. for(int i = sz; i <= n + sz - 1; i++){
  16. t[i] = a[i - sz + 1];
  17. }
  18. for(int i = sz + n; i <= sz + sz - 1; i++){
  19. t[i] = -inf;
  20. }
  21. for(int i = sz - 1; i >= 1; i--){
  22. t[i] = t[i * 2] + t[i * 2 + 1];
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement