#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} int M = 4; struct S{ vector> v; int s; }; S op(S a, S b){ vector> v(4, vector(4)); rep(ia, 4) for(int ja = ia; ja < 4; ja++){ for(int ib = ja; ib < 4; ib++) for(int jb = ib; jb < 4; jb++){ chmax(v[ia][jb], a.v[ia][ja] + b.v[ib][jb]); } } S res = {v, a.s + b.s}; return res; } S e(){ return (S){vector>(4, vector(4)), 0}; } using F = int; int INF = 1001001001; S mapping(F f, S x){ if(f == INF) return x; vector> v(4, vector(4)); v[f][f] = x.s; return S{v, x.s}; } F composition(F f, F g){ if(f == INF) return g; else return f; } F id(){ return INF; } vector>> memo(4, vector>(4, vector(4))); int main(){ rep(i, 4) memo[i][i][i] = 1; int n; cin >> n; vector a(n); cin >> a; rep(i, n) a[i]--; vector init(n); rep(i, n){ init[i].v = memo[a[i]]; init[i].s = 1; } lazy_segtree seg(init); int q; cin >> q; rep(i, q){ int t, l, r; cin >> t >> l >> r; l--; r--; if(t == 1){ auto res = seg.prod(l, r + 1); int ans = 0; rep(i, 4) for(int j = i; j < 4; j++) chmax(ans, res.v[i][j]); cout << ans << "\n"; } if(t == 2){ int x; cin >> x; x--; seg.apply(l, r + 1, x); } } return 0; }