#include #include using namespace std; using namespace atcoder; using lint = long long; struct S { lint left, sum, right; }; S op(S a, S b) { S res; if (a.left == 0) { res = b; } else if (b.right == 0) { res = a; res.sum++; } else { res.left = a.left; res.sum = (a.right == b.left ? a.sum + b.sum : a.sum + b.sum + 1); res.right = b.right; } return res; } S e() { return {0LL, 0LL, 0LL}; } S mapping(lint x, S s) { return {s.left + x, s.sum, s.right + x}; } lint composition(lint f, lint g) { return f + g; } lint id() { return 0LL; } int main() { int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } lazy_segtree seg(n); for (int i = 0; i < n; i++) { seg.set(i, {a[i], 0LL, a[i]}); } while (q--) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { lint x; cin >> x; seg.apply(l, r + 1, x); } else { cout << seg.prod(l, r + 1).sum << endl; } } }