#include using namespace std; #include using namespace atcoder; using ll = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using VS = vector; using P = pair; using VP = vector

; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define out(x) cout << x << endl #define dout(x) cout << fixed << setprecision(10) << x << endl #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(x) (int)(x.size()) #define re0 return 0 #define pcnt __builtin_popcountll template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int inf = 1e9; constexpr ll INF = 1e18; //using mint = modint1000000007; using mint = modint998244353; struct S{ VVL x; ll len; S():x(4,VL(4)),len(0){} }; using F = ll; S op(S a,S b){ S c; rep(d,4)rep(i,4){ ll j = i+d; if(j >= 4) continue; ll mx = 0; for(ll k = i;k <= j;k++){ chmax(mx,a.x[i][k]); chmax(c.x[i][j],mx+b.x[k][j]); } } c.len = a.len+b.len; return c; } S e(){ S res; res.len = 0; return res; } S mapping(F f,S x){ if(f==INF){ return x; } rep(i,4)rep(j,4) x.x[i][j] = 0; x.x[f][f] = x.len; return x; } F composition(F f,F g){ if(f==INF) return g; else return f; } F id(){ return INF; } int main(){ ll n; cin >> n; vector v(n); rep(i,n){ ll a; cin >> a; a--; v[i].len = 1; v[i].x[a][a] = 1; } lazy_segtree seg(v); ll q; cin >> q; rep(qi,q){ ll t,l,r; cin >> t >> l >> r; l--; if(t==1){ ll ans = 0; rep(i,4)rep(j,i+1) chmax(ans,seg.prod(l,r).x[j][i]); out(ans); } if(t==2){ ll x; cin >> x; x--; seg.apply(l,r,x); } } }