Advertisement
artemgf

Нереальная история

Jun 13th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #pragma once
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define _USE_MATH_DEFINES
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <stdio.h>
  11. #include <cmath>
  12. #include <math.h>
  13. #include <queue>
  14. #include <stack>
  15. #include <climits>
  16. #include <deque>
  17. #include <ctime>
  18. #include <iomanip>
  19. #include <bitset>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef unsigned long long ull;
  27. typedef unsigned int ui;
  28.  
  29. #define mh() make_heap()
  30. #define poph() pop_heap()
  31. #define pushh() push_heap()
  32. #define sor(n) n.begin(), n.end()
  33. #define rsor(n) n.rbegin(), n.rend()
  34. #define mp make_pair
  35. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  36. #define p(T) pair<T,T>
  37. #define toch(x) cout.precision(x), cout.setf(ios::fixed)
  38. #define znac(l) abs(l)/l
  39. #define IOS ios::sync_with_stdio(false)
  40. #define IOSB cin.tie(0), cout.tie(0);
  41. const ll ok = ll(1e9 + 7);
  42. const ll N = 131072;
  43.  
  44. ll tree[(N+1) * 2];
  45. ll check(ll v)
  46. {
  47.     ll ans = 0;
  48.     v += N-1;
  49.     ans += tree[v];
  50.     for (v = v >> 1; v; v = v >> 1)
  51.         ans += tree[v];
  52.     return ans;
  53. }
  54.  
  55. void sumot(ll v,ll tl, ll tr, ll l, ll r, ll val)
  56. {
  57.     if (l > r)
  58.         return;
  59.     if (tl == l&&tr == r)
  60.     {
  61.         tree[v] += val;
  62.     }
  63.     else
  64.     {
  65.         ll tm = (tr + tl) >> 1;
  66.         sumot(v << 1, tl, tm, l, min(tm, r), val);
  67.         sumot((v << 1) + 1, tm + 1, tr, max(tm + 1, l), r, val);
  68.     }
  69. }
  70. int main()
  71. {
  72.     IOSB;
  73.     IOS;
  74. #ifdef TheCompiler
  75.     files;
  76. #endif
  77.     ll n;
  78.     cin >> n;
  79.     ll a, b, c;
  80.     cin >> a >> b >> c;
  81.     sumot(1, 1, N, a, b, c);
  82.     for (int i = 1; i <= n; i++)
  83.     {
  84.         cin >> a >> b >> c;
  85.         sumot(1, 1, N, a, b, c);
  86.     }
  87.     for (int i = 1; i <= n; i++)
  88.     {
  89.         cout << check(i) << " ";
  90.     }
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement