CHưa xong
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
const int MOD = 1e9+7;
struct Node{
int value;
int type[4];
Node(){
value = 0;
for (int i=1;i <= 3;i++) type[i] = 0;
}
bool operator + (const Node& other) {
Node ret;
ret.value = value + other.value;
return ret;
}
void resetLazy() {
for (int i=1;i <= 3;i++) {
type[i] = 0;
}
}
} st[4*N];
void down(int id, int l, int r) {
int mid = l + (r-l)/2;
}
void build(int id, int l, int r) {
if (l == r) {
st[id].value = a[l];
return;
}
int mid = l + (r-l)/2;
st[id] = st[id*2] + st[id*2+1];
return;
}
void update(int id, int l, int r, int u, int v, int type, int val){
if (r < u || v < l) return;
if (u <= l && r <= v) {
if (type == 1) {
st[id].value += (r-l+1)*val;
st[id].value %= MOD;
st[id].type[type] += val;
st[id].type[type] %= MOD;
}
if (type == 2) {
st[id].value *= val;
st[id].value %= MOD;
st[id].type[type] += val;
st[id].type[type] %= MOD;
}
if (type == 3) {
st[id].resetLazy();
st[id].value = (r-l+1)*val;
st[id].value %= MOD;
st[id].type[type] += val;
st[id].type[type] %= MOD;
}
return;
}
int mid = l + (r-l)/2;
down(id, l, r);
update(id*2, l, mid, u, v, type, val);
update(id*2+1, mid+1,r , u, v, type, val);
st[id] = st[id*2] + st[id*2+1];
return;
}
int get(int id, int l, int r, int u, int v) {
if (u <= l && r <= v)
return st[id].value;
if (r < u || v < l)
return 0;
int mid = l + (r-l)/2;
return (get(id*2, l, mid, u, v) + get(id*2+1, mid+1, r, u, v))%MOD;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> numQ;
for (int i=1;i <= n;i++)
cin >> a[i];
build(1, 1, n);
while(numQ--) {
int type, l, r;
cin >> type >> l >> r;
if (type != 4) {
int x; cin >> x;
update(1, 1, n, l, r, type, x);
}
else cout << get(1, 1, n, l, r) << endl;
}
return 0;
}