#include #include using namespace std; using namespace atcoder; struct S { int sz; array, 4> cnt; }; S e() { S res; res.sz = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { res.cnt[i][j] = 0; } } return res; } S op(S a, S b) { S res = e(); res.sz = a.sz + b.sz; 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++) { res.cnt[i][l] = max(res.cnt[i][l], a.cnt[i][j] + b.cnt[k][l]); } } } } return res; } S mapping(int f, S x) { if (f == -1) { return x; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { x.cnt[i][j] = 0; } } x.cnt[f][f] = x.sz; return x; } int composition(int f, int g) { if (f == -1) { return g; } return f; } int id() { return -1; } void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector a(n, e()); for (int i = 0; i < n; i++) { int x; cin >> x; x--; a[i].sz = 1; a[i].cnt[x][x] = 1; } lazy_segtree seg(a); int q; cin >> q; for (; q--;) { int type; cin >> type; if (type == 1) { int l, r; cin >> l >> r; cout << seg.prod(l - 1, r).cnt[0][3] << "\n"; } else { int l, r, x; cin >> l >> r >> x; seg.apply(l - 1, r, x - 1); } } }