SHARE
TWEET

Untitled

lalalalalalalaalalla Oct 16th, 2019 83 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) {
  84.         if (a.l + a.lm == b.rm) {
  85.             c.l = a.l + b.l;
  86.         }
  87.     }
  88.     if (b.r == r - m) {
  89.         if (a.rm + a.r == b.lm) {
  90.             c.r = a.r + b.r;
  91.             c.rm = a.rm;
  92.         }
  93.     }
  94.     c.ans = max(c.ans, max(c.l, c.r));
  95.     return c;
  96. }
  97.  
  98. int n;
  99. vector<node> t;
  100. vector<int> a, mod;
  101.  
  102. void push(int v) {
  103.     if (mod[v] != INF) {
  104.         mod[2 * v + 1] = mod[2 * v + 2] = mod[v];
  105.         mod[v] = INF;
  106.     }
  107. }
  108.  
  109. void build(int v, int l, int r) {
  110.     if (r - l == 1) {
  111.         t[v] = node(1, a[l], 1, a[l], 1);
  112.         mod[v] = INF;
  113.         return;
  114.     }
  115.     int m = (l + r) / 2;
  116.     build(2 * v + 1, l, m);
  117.     build(2 * v + 2, m, r);
  118.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  119. }
  120.  
  121. void update(int v, int l, int r, int askl, int askr, int val) {
  122.     if (l >= askr || r <= askl) {
  123.         return;
  124.     }
  125.     if (l >= askl && r <= askr) {
  126.         mod[v] = val;
  127.         return;
  128.     }
  129.     int m = (l + r) / 2;
  130.     push(v);
  131.     update(2 * v + 1, l, m, askl, askr, val);
  132.     update(2 * v + 2, m, r, askl, askr, val);
  133.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  134. }
  135.  
  136. node get_ans(int v, int l, int r, int askl, int askr) {
  137.     if (l >= askr || r <= askl) return node();
  138.     if (l >= askl && r <= askr) {
  139.         if (mod[v] != INF) {t[v] = node(1, mod[v], 1, mod[v], 1); mod[v] = INF;}
  140.         return t[v];
  141.     }
  142.     int m = (l + r) / 2;
  143.     push(v);
  144.     node first = get_ans(2 * v + 1, l, m, askl, askr), second = get_ans(2 * v + 2, m, r, askl, askr);
  145.     t[v] = merge(t[2 * v + 1], t[2 * v + 2], l, m, r);
  146.     return merge(first, second, l, m, r);
  147. }
  148.  
  149. signed main() {
  150.     ios_base::sync_with_stdio(0);
  151.     cin.tie(0);
  152.     cout.tie(0);
  153.     int n;
  154.     cin >> n;
  155.     a.resize(n);
  156.     t.resize(4 * n);
  157.     mod.assign(4 * n, INF);
  158.     for (auto& k : a) cin >> k;
  159.     build(0, 0, n);
  160.     int q;
  161.     cin >> q;
  162.     char t;
  163.     int l, r, val;
  164.     while (q--) {
  165.         cin >> t >> l >> r;
  166.         --l;
  167.         if (t == '+') {
  168.             cin >> val;
  169.             update(0, 0, n, l, r, val);
  170.         } else {
  171.             cout << get_ans(0, 0, n, l, r).ans << "\n";
  172.         }
  173.     }
  174. }
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