#include // #include // #include using namespace std; // using namespace atcoder; // using bint = boost::multiprecision::cpp_int; using ll = long long; using ull = unsigned long long; using P = pair; using vi = vector; using vvi = vector; using vvvi = vector; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define sz(c) ((ll)(c).size()) #define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin()) // #define MOD 1000000007 #define MOD 998244353 templateusing min_priority_queue=priority_queue,greater>; templateostream&operator<<(ostream&os,vector&v){for(int i = 0;i < v.size();i++)os<istream&operator>>(istream&is,vector&v){for(T&in:v)is>>in;return is;} templateostream&operator<<(ostream&os,pair&p){os<istream&operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} template class LazySegtree{ public: using F = function; using G = function; using H = function; int n,height; F f; G g; H h; T ti; E ei; vector dat; vector laz; LazySegtree(F f,G g,H h,T ti,E ei): f(f),g(g),h(h),ti(ti),ei(ei){} void init(int N){ n = 1;height = 0; while(n < N)n <<= 1,height++; dat.assign(n << 1,ti); laz.assign(n << 1,ei); } void build(const vector &v){ int N = v.size(); init(N); for(int i = 0;i < N;i++)dat[i+n] = v[i]; for(int i = n-1;i > 0;i--)dat[i] = f(dat[(i<<1)|0],dat[(i<<1)|1]); } inline T reflect(int k){ return (laz[k] == ei ? dat[k] : g(dat[k],laz[k])); } inline void eval(int k){ if(laz[k] == ei)return; laz[(k<<1)|0] = h(laz[(k<<1)|0],laz[k]); laz[(k<<1)|1] = h(laz[(k<<1)|1],laz[k]); dat[k] = reflect(k); laz[k] = ei; } inline void thrust(int k){ for(int i = height;i > 0;i--)eval(k >> i); } inline void recalc(int k){ while(k >>= 1)dat[k] = f(reflect((k << 1)|0),reflect((k << 1)|1)); } void update(int a,int b,E x){ thrust(a+=n); thrust(b+=n-1); for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){ if(l & 1)laz[l] = h(laz[l],x),l++; if(r & 1)r--,laz[r] = h(laz[r],x); } recalc(a); recalc(b); } void set_val(int a,T x){ thrust(a+=n); dat[a] = x;laz[a] = ei; recalc(a); } T get(int a,int b){ thrust(a+=n); thrust(b+=n-1); T vl = ti,vr = ti; for(int l = a,r = b+1;l < r;l >>= 1,r >>= 1){ if(l & 1)vl = f(vl,reflect(l++)); if(r & 1)vr = f(reflect(--r),vr); } return f(vl,vr); } }; struct e{ ll dp[4][4],L; e(){ rep(i,4)rep(j,4)dp[i][j] = 0; L = 0; } }; int main(){ ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector a(n); rep(i,n){ a[i].L = 1; int g;cin >> g; g--; rep(j,4)rep(k,4)if(j <= g && g <= k)a[i].dp[j][k] = 1; } auto f = [](e a,e b){ if(a.L == 0)return b; if(b.L == 0)return a; e c; rep(i,4)rep(j,4){ if(i <= j){ for(int k = i;k <= j;k++){ c.dp[i][j] = max(c.dp[i][j],a.dp[i][k]+b.dp[k][j]); } } } c.L = a.L + b.L; return c; }; auto g = [](e a,int x){ if(x == -1 || a.L == 0)return a; e c; c.L = a.L; rep(i,4)rep(j,4){ if(i <= x && x <= j){ c.dp[i][j] = a.L; } } return c; }; auto h = [](int a,int b){ if(b == -1)return a; return b; }; e ti; LazySegtree seg(f,g,h,ti,-1); seg.build(a); int Q; cin >> Q; while(Q--){ int t,l,r; cin >> t >> l >> r; l--; if(t == 1){ e res = seg.get(l,r); cout << res.dp[0][3] << "\n"; }else{ int x;cin >> x; x--; seg.update(l,r,x); } } return 0; }