#include #include using namespace std; using ll = long long; using S = array; using F = array; S e(){return S({0, 0, 0});} S op(S l, S r){ for(int i = 0; i < 3; i++) l[i] += r[i]; return l; } S mapping(F f, S x){ S res{}; if(f[1] & 1) swap(x[0], x[1]); x[2] += (x[0] + x[1]) * f[1]; if(f[0] == 1) x[2] = x[1]; if(f[2] & 1) swap(x[0], x[1]); x[2] += (x[0] + x[1]) * f[2]; return x; } F composition(F f, F g){ if(f[0] == 0) return S({g[0], g[1], g[2] + f[1] + f[2]}); return S({1, g[1] + g[2] + f[1], f[2]}); } F id(){return F({0, 0, 0});} int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; vector tmp(N); for(int i = 0; i < N; i++){ int v; cin >> v; tmp[i] = S({1 - v % 2, v % 2, v}); } atcoder::lazy_segtree seg(tmp); while(Q--){ int cmd, l, r, x; cin >> cmd >> l >> r; l--; if(cmd == 1){ seg.apply(l, r, F({1, 0, 0})); }else if(cmd == 2){ cin >> x; seg.apply(l, r, F({0, 0, x})); }else{ cout << seg.prod(l, r)[2] << '\n'; } } }