#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=0;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif struct S { vector> v; int len; }; S op(S a, S b){ S c; c.v = vector>(4, vector(4)); for(int i=0;i<4;i++) for(int j=0;j<4;j++){ c.v[i][j] = max(a.v[i][j],b.v[i][j]); } for(int i=0;i<4;i++){ for(int j=i;j<4;j++){ for(int k=j;k<4;k++){ for(int l=k;l<4;l++){ c.v[i][l] = max(c.v[i][l], a.v[i][j]+b.v[k][l]); } } } } c.len = a.len + b.len; return c; } S e(){ S c; c.v = vector>(4, vector(4)); c.len = 0; return c; } S mapping(int f, S a) { if(f==-1) return a; a.v = vector>(4, vector(4)); a.v[f][f] = a.len; return a; } int composition(int f, int g) { if(f==-1) return g; return f; } int id(){ return -1; } int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; lazy_segtree seg(n); rep(i,n){ --a[i]; S c; c.v = vector>(4,vector(4)); c.v[a[i]][a[i]] = 0; c.len = 1; seg.set(i,c); } int q; cin >> q; while(q--){ int t; cin >> t; if(t==1){ int l, r; cin >> l >> r; --l; auto vs = seg.prod(l,r); int ans = 0; dbg(vs.v); rep(i,4) rep(j,4) { ans = max(ans, vs.v[i][j]); } cout<> l >> r >> x; --l; --x; seg.apply(l,r,x); } } return 0; }