### 代码如下

#include <bits/stdc++.h>
#define LL long long
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define N 100005
using namespace std;
int sum[N * 4], add[N * 4], col[N * 4], mul[N * 4];
void pushup(int rt){
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void pushdown(int rt, int x){
if(col[rt] != -1){
mul[rt<<1] = mul[rt<<1|1] = 1;
sum[rt<<1] = col[rt] * (x - x / 2);
sum[rt<<1|1] = col[rt] * (x / 2);
col[rt<<1] = col[rt<<1|1] = col[rt];
col[rt] = -1;
}
if(mul[rt] != 1){
int c = mul[rt];
mul[rt<<1] *= c;
mul[rt<<1|1] *= c;
sum[rt<<1] *= c;
sum[rt<<1|1] *= c;
mul[rt] = 1;
}
sum[rt<<1] += add[rt] * (x - x / 2);
sum[rt<<1|1] += add[rt] * (x / 2);
}
}
void build(int l, int r, int rt){
if(l == r){
scanf("%d", &sum[rt]);
return;
}
int m = l + r >> 1;
build(lson);
build(rson);
pushup(rt);
}
void update(int l, int r, int rt, int a, int b, int c, int o){
if(l >= a && r <= b){
if(o == 1){//set
mul[rt] = 1;
sum[rt] = c * (r - l + 1);
col[rt] = c;
}
else if(o == 2){//cheng
mul[rt] *= c;
sum[rt] *= c;
}
else{//jia
sum[rt] += c * (r - l + 1);
}
return;
}
pushdown(rt, r-l+1);
int m = l + r >> 1;
if(a <= m) update(lson, a, b, c, o);
if(b > m) update(rson, a, b, c, o);
pushup(rt);
}
int query(int l, int r, int rt, int a, int b){
if(l >= a && r <= b) return sum[rt];
pushdown(rt, r-l+1);
int m = l + r >> 1, ans = 0;
if(a <= m) ans += query(lson, a, b);
if(b > m) ans += query(rson, a, b);
return ans;
}
int main(){
int i, j, n, m, o, a, b, c;
scanf("%d%d", &n, &m);
for(i = 1; i <= n * 4; i++){
mul[i] = 1;
col[i] = -1;
}
build(1, n, 1);
while(m--){
scanf("%d%d%d", &o, &a, &b);
if(o == 4) printf("%d\n", query(1, n, 1, a, b));
else{
scanf("%d", &c);
update(1, n, 1, a, b, c, o);
}
}
return 0;
}