#line 2 "/home/kowerkoint/workspace/CompPro-Make/library/KowerKoint/stl-expansion.hpp" #include template std::istream& operator>>(std::istream& is, std::pair& p) { is >> p.first >> p.second; return is; } template std::istream& operator>>(std::istream& is, std::array& a) { for (size_t i = 0; i < N; ++i) { is >> a[i]; } return is; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& e : v) is >> e; return is; } template std::ostream& operator<<(std::ostream& os, const std::pair& p) { os << p.first << " " << p.second; return os; } template std::ostream& operator<<(std::ostream& os, const std::array& a) { for (size_t i = 0; i < N; ++i) { os << a[i] << (i + 1 == a.size() ? "" : " "); } return os; } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { for (size_t i = 0; i < v.size(); ++i) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } #line 3 "/home/kowerkoint/workspace/CompPro-Make/library/KowerKoint/base.hpp" using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define END(...) { print(__VA_ARGS__); return; } using VI = vector; using VVI = vector; using VVVI = vector; using ll = long long; using VL = vector; using VVL = vector; using VVVL = vector; using ull = unsigned long long; using VUL = vector; using VVUL = vector; using VVVUL = vector; using VD = vector; using VVD = vector; using VVVD = vector; using VS = vector; using VVS = vector; using VVVS = vector; using VC = vector; using VVC = vector; using VVVC = vector; using P = pair; using VP = vector

; using VVP = vector; using VVVP = vector; using LP = pair; using VLP = vector; using VVLP = vector; using VVVLP = vector; template using PQ = priority_queue; template using GPQ = priority_queue, greater>; constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001ll; constexpr int DX[] = {1, 0, -1, 0}; constexpr int DY[] = {0, 1, 0, -1}; void print() { cout << '\n'; } template void print(const T &t) { cout << t << '\n'; } template void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } #ifdef DEBUG void dbg() { cerr << '\n'; } template void dbg(const T &t) { cerr << t << '\n'; } template void dbg(const Head &head, const Tail &... tail) { cerr << head << ' '; dbg(tail...); } #else template void dbg(const Args &... args) {} #endif template vector> split(typename vector::const_iterator begin, typename vector::const_iterator end, T val) { vector> res; vector cur; for(auto it = begin; it != end; it++) { if(*it == val) { res.push_back(cur); cur.clear(); } else cur.push_back(*it); } res.push_back(cur); return res; } vector split(typename string::const_iterator begin, typename string::const_iterator end, char val) { vector res; string cur = ""; for(auto it = begin; it != end; it++) { if(*it == val) { res.push_back(cur); cur.clear(); } else cur.push_back(*it); } res.push_back(cur); return res; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template pair> compress(const vector &a) { int n = a.size(); vector x; REP(i, n) x.push_back(a[i]); sort(ALL(x)); x.erase(unique(ALL(x)), x.end()); VI res(n); REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin(); return make_pair(res, x); } template auto rle(It begin, It end) { vector> res; if(begin == end) return res; auto pre = *begin; int num = 1; for(auto it = begin + 1; it != end; it++) { if(pre != *it) { res.emplace_back(pre, num); pre = *it; num = 1; } else num++; } res.emplace_back(pre, num); return res; } template vector> rle_sort(It begin, It end) { vector cloned(begin, end); sort(ALL(cloned)); auto e = rle(ALL(cloned)); sort(ALL(e), [](const auto& l, const auto& r) { return l.second < r.second; }); return e; } template pair, vector> factorial(int n) { vector res(n+1), rev(n+1); res[0] = 1; REP(i, n) res[i+1] = res[i] * (i+1); rev[n] = 1 / res[n]; for(int i = n; i > 0; i--) { rev[i-1] = rev[i] * i; } return make_pair(res, rev); } #line 2 "main.cpp" void solve(){ int n; cin >> n; VI a(n); cin >> a; set> a_rle; // st, ed, val REP(i, n) a_rle.emplace(i, i+1, a[i]); auto get_sub_rle = [&](int l, int r) { vector> res; auto it = a_rle.lower_bound({l, 0, 0}); if(it != a_rle.begin() && l < get<1>(*prev(it))) { auto p = prev(it); auto [pl, pr, px] = *p; res.emplace_back(l, min(r, pr), px); } while(it != a_rle.end() && get<1>(*it) <= r) { res.emplace_back(get<0>(*it), get<1>(*it), get<2>(*it)); it++; } if(it != a_rle.end() && get<0>(*it) < r) { res.emplace_back(get<0>(*it), r, get<2>(*it)); } return res; }; int q; cin >> q; while(q--) { int t, l, r; cin >> t >> l >> r; l--; if(t == 1) { auto sub_rle = get_sub_rle(l, r); /* dbg("==="); */ /* for(auto [st, ed, val] : sub_rle) { */ /* dbg(st, ed, val); */ /* } */ array dp{0}; for(auto [st, ed, val] : sub_rle) { dp[val-1] = *max_element(dp.begin(), dp.begin() + val) + ed - st; } print(*max_element(ALL(dp))); } else { int x; cin >> x; auto it = a_rle.lower_bound({l, 0, 0}); if(it != a_rle.begin() && l < get<1>(*prev(it))) { auto p = prev(it); auto [pl, pr, px] = *p; a_rle.erase(p); a_rle.emplace(pl, l, px); } while(it != a_rle.end() && get<1>(*it) <= r) { it = a_rle.erase(it); } if(it != a_rle.end() && get<0>(*it) < r) { auto [pl, pr, px] = *it; a_rle.erase(it); a_rle.emplace(r, pr, px); } a_rle.emplace(l, r, x); /* dbg("==="); */ /* for(auto [st, ed, val] : a_rle) { */ /* dbg(st, ed, val); */ /* } */ } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); int t = 1; // cin >> t; for(int case_id = 1; case_id <= t; case_id++) solve(); return 0; }