#include<iostream>
#include<set>
#include<vector>
using namespace std;
const int N = 3e5+10;
const int MOD = 1000000007;
struct Node {
int lf, rt;
mutable long long val;
Node(int L,int R = 0,long long V = 0) : lf(L), rt(R), val(V) {}
bool operator< (const Node &a) const {
return lf < a.lf;
}
};
int n, T, a[N];
set<Node> Chtholly;
vector<Node> v1, v2;
inline auto split(int pos) {
auto it = Chtholly.lower_bound(Node(pos));
if (it->lf == pos && it != Chtholly.end()) return it;
--it;
if (it->rt < pos) return Chtholly.end();
long long v = it->val;
int l = it->lf, r = it->rt;
Chtholly.erase(it);
Chtholly.insert(Node(l,pos-1,v));
return Chtholly.insert(Node(pos,r,v)).first;
}
inline void assign(int l,int r,long long v) {
auto itR = split(r+1), itL = split(l);
Chtholly.erase(itL,itR);
Chtholly.insert(Node(l,r,v));
}
inline void add(int l,int r,long long v) {
auto itR = split(r+1), itL = split(l);
for (auto it = itL; it != itR; ++it)
it->val += v;
}
inline void copy(int l1,int r1,int l2,int r2) {
auto itR = split(r1+1), itL = split(l1), _itR = split(r2+1), _itL = split(l2);
int delta = l2-l1;
v1.clear();
for (auto it = itL; it != itR; ++it)
v1.push_back(Node(it->lf+delta,it->rt+delta,it->val));
Chtholly.erase(_itL,_itR);
for (auto it:v1) {
Chtholly.insert(it);
}
}
inline void swap(int l1,int r1,int l2,int r2) {
auto itR = split(r1+1), itL = split(l1), _itR = split(r2+1), _itL = split(l2);
int delta = l2-l1;
v1.clear(), v2.clear();
for (auto it = itL; it != itR; ++it)
v1.push_back(Node(it->lf+delta,it->rt+delta,it->val));
for (auto it = _itL; it != _itR; ++it)
v2.push_back(Node(it->lf-delta,it->rt-delta,it->val));
if (abs(l2-l1) != 1) {
Chtholly.erase(_itL,_itR);
Chtholly.erase(itL,itR);
} else {
Chtholly.erase(itL);
Chtholly.erase(_itL);
}
for (auto it:v1) Chtholly.insert(it);
for (auto it:v2) Chtholly.insert(it);
}
inline void reverse(int l,int r) {
auto itR = split(r+1), itL = split(l);
v1.clear();
for (auto it = itL; it != itR; ++it)
v1.push_back(Node(it->lf,it->rt,it->val));
Chtholly.erase(itL,itR);
for (auto it:v1) Chtholly.insert(Node(r-it.rt+l,r-it.lf+l,it.val));
}
inline int sum(int l,int r) {
auto itR = split(r+1), itL = split(l);
long long res = 0;
for (auto it = itL; it != itR; ++it) {
res += (it->rt-it->lf+1)*it->val;
res %= MOD;
}
return res%MOD;
}
inline void debug(void) {
for (auto it:Chtholly)
for (int i = it.lf; i <= it.rt; ++i)
cout << it.val%MOD << " ";
cout << "\n";
}
signed main() {
cin >> n >> T;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
Chtholly.insert(Node(i,i,a[i]));
}
while (T--) {
int opt; cin >> opt;
int l, r, l1, r1, v;
switch(opt) {
case 1:
cin >> l >> r;
cout << sum(l,r) << "\n"; break;
case 2:
cin >> l >> r >> v;
assign(l,r,v); break;
case 3:
cin >> l >> r >> v;
add(l,r,v); break;
case 4:
cin >> l >> r >> l1 >> r1;
copy(l,r,l1,r1); break;
case 5:
cin >> l >> r >> l1 >> r1;
swap(l,r,l1,r1); break;
case 6:
cin >> l >> r;
reverse(l,r); break;
}
}
debug();
return 0;
}