#include #include #include #include using namespace std; long long isqrt(long long x) { long long res = sqrt(x); while ((res + 1) * (res + 1) <= x) ++res; while (res * res > x) --res; return res; } // https://nyaannyaan.github.io/library/segment-tree/segment-tree-beats-abstract.hpp template struct Beats { int n, log; vector v; template Beats(vector& vc) { n = 1, log = 0; while (n < (int)vc.size()) n <<= 1, log++; v.resize(2 * n); for (int i = 0; i < (int)vc.size(); ++i) v[i + n] = Node(vc[i]); for (int i = n - 1; i; --i) _update(i); } template void apply(int l, int r, T x) { if (l == r) return; l += n, r += n; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) _push(l >> i); if (((r >> i) << i) != r) _push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) _apply(l++, x); if (r & 1) _apply(--r, x); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) _update(l >> i); if (((r >> i) << i) != r) _update((r - 1) >> i); } } template void query(int l, int r, const F& f) { if (l == r) return; l += n, r += n; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) _push(l >> i); if (((r >> i) << i) != r) _push((r - 1) >> i); } while (l < r) { if (l & 1) f(v[l++]); if (r & 1) f(v[--r]); l >>= 1; r >>= 1; } } private: void _push(int i) { v[i].push(v[2 * i + 0], v[2 * i + 1]); } void _update(int i) { v[i].update(v[2 * i + 0], v[2 * i + 1]); } template void _apply(int i, T x) { bool res = v[i].apply(x); if (i < n && res == false) { _push(i); _apply(i * 2 + 0, x); _apply(i * 2 + 1, x); _update(i); } } }; struct Node { long long sum; int val; int siz; bool same; Node(int v = 0) : sum(v), val(v), siz(1), same(true) {} void query2(int x) { sum = x * (long long)siz; val = x; same = true; } void push(Node& l, Node& r) { if (same) l.query2(val), r.query2(val); } void update(Node& l, Node& r) { sum = l.sum + r.sum; val = l.val; siz = l.siz + r.siz; same = (l.same && r.same && l.val == r.val); } bool apply(pair p) { if (p.first == 1) { if (same) { val = isqrt(val); sum = val * (long long)siz; return true; } else return false; } else { val = p.second; sum = val * (long long)siz; same = true; return true; } } }; int main() { int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; ++i) cin >> a[i]; Beats sg(a); for (int i = 0; i < q; i++) { int t; cin >> t; if (t == 0) { int l, r; cin >> l >> r; long long ans = 0; sg.query(l, r, [&](Node& nd) {ans += nd.sum;}); cout << ans << '\n'; } else if (t == 1) { int l, r, x; cin >> l >> r >> x; sg.apply(l, r, make_pair(0, x)); } else if (t == 2) { int l, r; cin >> l >> r; sg.apply(l, r, make_pair(1, 0)); } } }