SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 14th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17. #include <unordered_set>
  18. #include <cassert>
  19.  
  20.  
  21. //#pragma GCC optimize("Ofast,no-stack-protector")
  22. #pragma GCC optimize("O3")
  23. //#pragma GCC target("avx2")
  24. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
  25. //#pragma GCC optimize("unroll-loops")
  26. #pragma GCC optimize("fast-math")
  27. //#pragma GCC optimize("section-anchors")
  28. //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  29. //#pragma GCC optimize("vpt")
  30. //#pragma GCC optimize("rename-registers")
  31. //#pragma GCC optimize("move-loop-invariants")
  32. //#pragma GCC optimize("unswitch-loops")
  33. //#pragma GCC optimize("function-sections")
  34. //#pragma GCC optimize("data-sections")
  35. //#pragma GCC optimize("branch-target-load-optimize")
  36. //#pragma GCC optimize("branch-target-load-optimize2")
  37. //#pragma GCC optimize("btr-bb-exclusive")
  38. //#pragma GCC optimize("O0")
  39.  
  40.  
  41. #define int long long
  42. #define ll long long
  43. #define ull unsigned long long
  44. #define all(a) a.begin(), a.end()
  45. #define pii pair<int, int>
  46. #define pb push_back
  47. #define ld long double
  48.  
  49.  
  50. using namespace std;
  51.  
  52. //const int INF = 1e13;
  53. //const int mod = 2600000069;
  54. //const int p = 179;
  55.  
  56. int n;
  57. vector<int> a, t, mod;
  58.  
  59. void build(int v, int l, int r) {
  60.     if (r - l == 1) {
  61.         t[v] = a[l];
  62.         return;
  63.     }
  64.     int m = (l + r) / 2;
  65.     build(2 * v + 1, l, m);
  66.     build(2 * v + 2, m, r);
  67.     t[v] = max(t[2 * v + 1], t[2 * v + 2]);
  68. }
  69.  
  70. void push(int v) {
  71.     mod[2 * v + 1] += mod[v];
  72.     mod[2 * v + 2] += mod[v];
  73.     mod[v] = 0;
  74. }
  75.  
  76. void update(int v, int l, int r, int askl, int askr, int val) {
  77.     if (l >= askr || r <= askl) {
  78.         return;
  79.     }
  80.     if (l >= askl && r <= askr) {
  81.         mod[v] += val;
  82.         return;
  83.     }
  84.     push(v);
  85.     int m = (l + r) / 2;
  86.     update(2 * v + 1, l, m, askl, askr, val);
  87.     update(2 * v + 2, m, r, askl, askr, val);
  88.     t[v] = max(t[2 * v + 1] + mod[2 * v + 1], t[2 * v + 2] + mod[2 * v + 2]);
  89. }
  90.  
  91. int get_ans(int v, int l, int r, int askl, int askr) {
  92.     if (l >= askr || r <= askl) {
  93.         return 0;
  94.     }
  95.     if (l >= askl && r <= askr) {
  96.         return t[v] + mod[v];
  97.     }
  98.     push(v);
  99.     int m = (l + r) / 2;
  100.     int first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  101.     t[v] = max(t[2 * v + 1] + mod[2 * v + 1], t[2 * v + 2] + mod[2 * v + 2]);
  102.     return max(first, second);
  103. }
  104.  
  105. signed main() {
  106.     ios_base::sync_with_stdio(0);
  107.     cin.tie(0);
  108.     cout.tie(0);
  109.     cin >> n;
  110.     a.resize(n);
  111.     t.resize(4 * n);
  112.     mod.assign(4 * n, 0);
  113.     for (int i = 0; i < n; i++) cin >> a[i];
  114.     build(0, 0, n);
  115.     int q;
  116.     cin >> q;
  117.     char t;
  118.     int l, r, val;
  119.     while(q--) {
  120.         cin >> t >> l >> r;
  121.         l--;
  122.         if (t == 'm') {
  123.             cout << get_ans(0, 0, n, l, r) << "\n";
  124.         } else {
  125.             cin >> val;
  126.             update(0, 0, n, l, r - 1, val);
  127.         }
  128.     }
  129. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top