Advertisement
ssrtatarin

Untitled

Jan 8th, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cassert>
  5. #include <algorithm>
  6. #include <map>
  7. #include <cmath>
  8. #include <stack>
  9. #include <iomanip>
  10. #include <set>
  11. #include <deque>
  12. #include <queue>
  13. #include <ctime>
  14.  
  15. using namespace std;
  16.  
  17. typedef __int128 lll;
  18. typedef long long ll;
  19. typedef double ld;
  20. ll inf = 1e9, mod = 1e9 + 7;
  21. const int N = 1e6;
  22. #define all(a) a.begin(),a.end()
  23. #define _GLIBCXX_DEBUG
  24.  
  25. ll a[N], u[N], tree[N];
  26.  
  27. void build(ll l, ll r, ll v) {
  28. if (l == r) {
  29. tree[v] = a[l];
  30. return;
  31. }
  32. ll m = (l + r) / 2;
  33. build(l, m, v + v);
  34. build(m + 1, r, v + v + 1);
  35. tree[v] = max(tree[v + v], tree[v + v + 1]);
  36. }
  37.  
  38. void push(ll l, ll r, ll v) {
  39. if (!u[v])
  40. return;
  41. tree[v] += u[v];
  42. if (l == r) {
  43. u[v] = 0;
  44. return;
  45. }
  46. u[v + v] += u[v];
  47. u[v + v + 1] += u[v];
  48. u[v] = 0;
  49. }
  50.  
  51. void change(ll l, ll r, ll v, ll la, ll ra, ll x) {
  52. push(l, r, v);
  53. if (l > ra || r < la)
  54. return;
  55. if (l >= la && r <= ra) {
  56. u[v] += x;
  57. push(l, r, v);
  58. return;
  59. }
  60. ll m = (l + r) / 2;
  61. change(l, m, v + v, la, ra, x);
  62. change(m + 1, r, v + v + 1, la, ra, x);
  63. tree[v] = max(tree[v + v], tree[v + v + 1]);
  64. }
  65.  
  66. ll ans(ll l, ll r, ll v, ll la, ll ra) {
  67. push(l, r, v);
  68. if (l > ra || r < la)
  69. return 0;
  70. if (l >= la && r <= ra)
  71. return tree[v];
  72. ll m = (l + r) / 2;
  73. return max(ans(l, m, v + v, la, ra), ans(m + 1, r, v + v + 1, la, ra));
  74. }
  75.  
  76. int main() {
  77. #ifdef anime
  78.  
  79. freopen("input1.txt", "r", stdin);
  80. freopen("outpu1.txt", "w", stdout);
  81. #endif
  82. srand(time(nullptr));
  83. ios_base::sync_with_stdio(false);
  84. cin.tie(nullptr);
  85. cout.tie(nullptr);
  86. ll n, k, i;
  87. cin >> n;
  88. for (i = 0; i < n; i++)
  89. cin >> a[i + 1];
  90. build(1, n, 1);
  91. cin >> k;
  92. while (k--) {
  93. char c;
  94. cin >> c;
  95. ll x, y;
  96. cin >> x >> y;
  97. if (c == 'a') {
  98. ll z;
  99. cin >> z;
  100. change(1, n, 1, x, y, z);
  101. } else
  102. cout << ans(1, n, 1, x, y) << '\n';
  103. }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement