#include using namespace std; using ll = long long; // #define int ll using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template T &chmin(T &a, const T &b) { return a = min(a, b); } template T &chmax(T &a, const T &b) { return a = max(a, b); } template bool IN(T a, T b, T x) { return a<=x&&x T ceil(T a, T b) { return a/b + !!(a%b); } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a,Ts... ts) { return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value==0>::type fill_v(T &t, const V &v) { t=v; } template typename enable_if::value!=0>::type fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); } template ostream &operator <<(ostream& out,const pair& a) { out<<'('< ostream &operator <<(ostream& out,const vector& a){ out<<'['; for(const T &i: a) out< ostream &operator <<(ostream& out, const set& a) { out<<'{'; for(const T &i: a) out< ostream &operator <<(ostream& out, const map& a) { out<<'{'; for(auto &i: a) out< struct segtree { ll n; vector dat; dat_type dat_d; vector lazy; lazy_type lazy_d; dat_type merge_dat(dat_type l, dat_type r) { dat_type ret; ret.sum = l.sum + r.sum; ret.max = max(l.max, r.max); ret.min = min(l.min, r.min); return ret; } segtree() {} segtree(int n_, dat_type dd, ll ld) : dat_d(dd), lazy_d(ld) { n = 1; while(n < n_) n *= 2; dat.assign(n*2-1, dat_d); lazy.assign(n*2-1, lazy_d); } void eval(int k, int l, int r) { if(lazy[k] == lazy_d) return; dat[k].sum = lazy[k] * (r-l); dat[k].max = dat[k].min = lazy[k]; if(k*2+1 < n*2-1) { lazy[2*k+1] = lazy[k]; lazy[2*k+2] = lazy[k]; } lazy[k] = lazy_d; } void update(int a, int b, ll x, int k, int l, int r) { eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] = x; eval(k, l, r); return; } int m = (l+r)>>1; update(a, b, x, 2*k+1, l, m); update(a, b, x, 2*k+2, m, r); dat[k] = merge_dat(dat[2*k+1], dat[2*k+2]); } void update(int a, int b, ll x) { update(a, b, x, 0, 0, n); } void update_gcd(int a, int b, ll x, int k, int l, int r) { eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b && dat[k].max == dat[k].min) { lazy[k] = __gcd(dat[k].max, x); eval(k, l, r); return; } int m = (l+r)>>1; update_gcd(a, b, x, 2*k+1, l, m); update_gcd(a, b, x, 2*k+2, m, r); dat[k] = merge_dat(dat[2*k+1], dat[2*k+2]); } void update_gcd(int a, int b, ll x) { update_gcd(a, b, x, 0, 0, n); } dat_type query(int a, int b, int k, int l, int r) { eval(k, l, r); if(b <= l || r <= a) return dat_d; if(a <= l && r <= b) return dat[k]; int m=(l+r)>>1; dat_type vl = query(a, b, 2*k+1, l, m); dat_type vr = query(a, b, 2*k+2, m, r); return merge_dat(vl, vr); } dat_type query(int a, int b) { return query(a, b, 0, 0, n); } }; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, q; cin >> n >> q; vector a(n); REP(i, n) cin >> a[i]; struct node { ll sum, max, min; node() : sum(0), max(-LLINF), min(LLINF) {} node(ll v) : sum(v), max(v), min(v) {} }; segtree seg(n, node(), -1); REP(i, n) seg.update(i, i+1, a[i]); while(q--) { ll type; cin >> type; if(type == 1) { ll l, r, x; cin >> l >> r >> x; l--, r--; seg.update(l, r+1, x); } else if(type == 2) { ll l, r, x; cin >> l >> r >> x; l--, r--; seg.update_gcd(l, r+1, x); } else if(type == 3) { ll l, r; cin >> l >> r; l--, r--; cout << seg.query(l, r+1).max << endl; } else if(type == 4) { ll l, r; cin >> l >> r; l--, r--; cout << seg.query(l, r+1).sum << endl; } // FOR(j, 444, 488) cout << seg.query(j, j+1).max << " "; // cout << endl; } return 0; }