SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 16th, 2019 70 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.  
  19.  
  20. //#pragma GCC optimize("Ofast,no-stack-protector")
  21. //#pragma GCC optimize("O3")
  22. //#pragma GCC target("avx2")
  23. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  24. //#pragma GCC optimize("unroll-loops")
  25. //#pragma GCC optimize("fast-math")
  26. //#pragma GCC optimize("section-anchors")
  27. //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  28. //#pragma GCC optimize("vpt")
  29. //#pragma GCC optimize("rename-registers")
  30. //#pragma GCC optimize("move-loop-invariants")
  31. //#pragma GCC optimize("unswitch-loops")
  32. //#pragma GCC optimize("function-sections")
  33. //#pragma GCC optimize("data-sections")
  34. //#pragma GCC optimize("branch-target-load-optimize")
  35. //#pragma GCC optimize("branch-target-load-optimize2")
  36. //#pragma GCC optimize("btr-bb-exclusive")
  37. //#pragma GCC optimize("O0")
  38.  
  39.  
  40. #define int long long
  41. #define ll long long
  42. #define ull unsigned long long
  43. #define all(a) a.begin(), a.end()
  44. #define pii pair<int, int>
  45. #define pb push_back
  46. #define ld long double
  47.  
  48.  
  49. using namespace std;
  50.  
  51. const int INF = 1e18;
  52. //const int mod = 2600000069;
  53. //const int p = 179;
  54.  
  55. struct node {
  56.     int l, r, lm, rm, ans;
  57.     node(int l_, int lm_, int r_, int rm_, int ans_) {
  58.         l = l_;
  59.         lm = lm_;
  60.         r = r_;
  61.         rm = rm_;
  62.         ans = ans_;
  63.     }
  64.     node() {
  65.         l = 0;
  66.         r = 0;
  67.         rm = INF;
  68.         lm = INF;
  69.         ans = 0;
  70.     }
  71. };
  72.  
  73. node merge(node a, node b, int l, int m, int r) {
  74.     node c;
  75.     c.l = a.l;
  76.     c.lm = a.lm;
  77.     c.r = b.r;
  78.     c.rm = b.rm;
  79.     c.ans = max(a.ans, b.ans);
  80.     if (a.r + a.rm == b.lm) {
  81.         c.ans = max(a.r + b.l, c.ans);
  82.     }
  83.     if (a.l == m - l && a.l + a.lm == b.lm) {
  84.         c.l = a.l + b.l;
  85.     }
  86.     if (b.r == r - m && a.rm + a.r == b.rm) {
  87.         c.r = a.r + b.r;
  88.         c.rm = a.rm;
  89.     }
  90.     c.ans = max(c.ans, max(c.l, c.r));
  91.     return c;
  92. }
  93.  
  94. int n;
  95. vector<node> t;
  96. vector<int> a, mod;
  97.  
  98. void push(int v) {
  99.     if (2 * v + 1 >= 4 * n) {
  100.         t[v].lm += mod[v];
  101.         t[v].rm += mod[v];
  102.         mod[v] = 0;
  103.         return;
  104.     }
  105.     t[v].lm += mod[v];
  106.     t[v].rm += mod[v];
  107.     mod[2 * v + 1] += mod[v];
  108.     mod[2 * v + 2] += mod[v];
  109.     mod[v] = 0;
  110. }
  111.  
  112. void build(int v, int l, int r) {
  113.     if (r - l == 1) {
  114.         t[v] = node(1, a[l], 1, a[l], 1);
  115.         return;
  116.     }
  117.     int m = (l + r) / 2;
  118.     build(2 * v + 1, l, m);
  119.     build(2 * v + 2, m, r);
  120.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  121. }
  122.  
  123. void update(int v, int l, int r, int askl, int askr, int val) {
  124.     if (l >= askr || r <= askl) {
  125.         return;
  126.     }
  127.     push(v);
  128.     if (l >= askl && r <= askr) {
  129.         mod[v] = val;
  130.         return;
  131.     }
  132.     int m = (l + r) / 2;
  133.     update(2 * v + 1, l, m, askl, askr, val);
  134.     update(2 * v + 2, m, r, askl, askr, val);
  135.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  136. }
  137.  
  138. node get_ans(int v, int l, int r, int askl, int askr) {
  139.     if (l >= askr || r <= askl) return node();
  140.     push(v);
  141.     if (l >= askl && r <= askr) {
  142.         return t[v];
  143.     }
  144.     int m = (l + r) / 2;
  145.     node ret = merge(get_ans(2 * v + 1, l, m, askl, askr), get_ans(2 * v + 2, m, r, askl, askr), l, m, r);
  146.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  147.     return ret;
  148. }
  149.  
  150. signed main() {
  151.     ios_base::sync_with_stdio(0);
  152.     cin.tie(0);
  153.     cout.tie(0);
  154.     int n;
  155.     cin >> n;
  156.     a.resize(n);
  157.     t.resize(4 * n);
  158.     mod.assign(4 * n, 0);
  159.     for (auto& k : a) cin >> k;
  160.     build(0, 0, n);
  161.     int q;
  162.     cin >> q;
  163.     char t;
  164.     int l, r, val;
  165.     while (q--) {
  166.         cin >> t >> l >> r;
  167.         --l;
  168.         if (t == '+') {
  169.             cin >> val;
  170.             update(0, 0, n, l, r, val);
  171.         } else {
  172.             cout << get_ans(0, 0, n, l, r).ans << "\n";
  173.         }
  174.     }
  175. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top