#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; template class ModInt { public: ModInt() :value(0) {} ModInt(long long val) :value((int)(val<0 ? MOD + val % MOD : val % MOD)) { } ModInt& operator+=(ModInt that) { value = value + that.value; if (value >= MOD)value -= MOD; return *this; } ModInt& operator-=(ModInt that) { value -= that.value; if (value<0)value += MOD; return *this; } ModInt& operator*=(ModInt that) { value = (int)((long long)value * that.value % MOD); return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt pow(long long k) const { ModInt n = *this, res = 1; while (k) { if (k & 1)res *= n; n *= n; k >>= 1; } return res; } ModInt inverse() const { long long a = value, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return ModInt(u); } int toi() const { return value; } private: int value; }; typedef ModInt<1000000007> mint; ostream& operator<<(ostream& os, const mint& x) { os << x.toi(); return os; } namespace Lz { struct P { mint a, f, c; }; P EP = { 0,0,1 }; struct Q { mint p, q, r; bool operator!=(Q x) { return p.toi() != x.p.toi() || q.toi() != x.q.toi() || r.toi() != x.r.toi(); } }; Q EQ = { 1,0,0 }; P f(P pl, P pr) { return P{ pl.a + pr.a,pl.f + pr.f,pl.c + pr.c }; } P g(P p, Q q) { return P{ p.a*q.p + p.f*q.q + p.c*q.r,p.f,p.c }; } Q h(Q qa, Q qb) { return Q{ qa.p*qb.p, qa.q*qb.p + qb.q, qa.r*qb.p + qb.r }; } } /* 遅延伝搬セグメント木 */ struct LazySegTree { int dataSize; vector value; vector lazy; LazySegTree(int n) : LazySegTree(vector(n, Lz::EP)){} LazySegTree(vector dat) { dataSize = 1; int n = (int)dat.size(); while (dataSize < n)dataSize *= 2; int treeSize = 2 * dataSize; value = vector(treeSize, Lz::EP); lazy = vector(treeSize, Lz::EQ); for (int i = 0; i < n; ++i) { value[dataSize+i] = dat[i]; } for (int i = dataSize - 1; i >= 0; --i) { value[i] = Lz::f(value[i * 2], value[i * 2 + 1]); } } void propagate(int index, int curL, int curR) { if (lazy[index]!=Lz::EQ) { int left = index * 2, right = index * 2 + 1; value[index] = g(value[index], lazy[index]); if (curR - curL > 1) { lazy[left] = Lz::h(lazy[left], lazy[index]); lazy[right] = Lz::h(lazy[right], lazy[index]); } lazy[index] = Lz::EQ; } } void update(int index, int curL, int curR, int givenL, int givenR, Lz::Q x) { propagate(index, curL, curR); if (curR <= givenL || givenR <= curL)return; if (givenL <= curL && curR <= givenR) { lazy[index] = Lz::h(lazy[index], x); propagate(index, curL, curR); } else { int mid = (curL + curR) / 2; update(index * 2, curL, mid, givenL, givenR, x); update(index * 2 + 1, mid, curR, givenL, givenR, x); value[index] = Lz::f(value[index * 2], value[index * 2 + 1]); } } void update(int l, int r, Lz::Q x) { update(1, 0, dataSize, l, r, x); } Lz::P query(int l, int r) { return query(1, 0, dataSize, l, r); } Lz::P query(int index, int curL, int curR, int givenL, int givenR) { if (curR <= givenL || givenR <= curL)return Lz::EP; propagate(index, curL, curR); if (givenL <= curL && curR <= givenR) { return value[index]; } else { int mid = (curL + curR) / 2; Lz::P resL = query(index * 2, curL, mid, givenL, givenR); Lz::P resR = query(index * 2 + 1, mid, curR, givenL, givenR); return Lz::f(resL, resR); } } }; void solve() { int N, M; cin >> N >> M; // フィボナッチ数列は事前に計算 vector a(N, Lz::EP); a[1].f = 1; for (int i = 2; i < N; ++i)a[i].f = a[i - 2].f + a[i - 1].f; LazySegTree tree(a); rep(ITER, M) { int q, l, r, k; cin >> q >> l >> r >> k; r++; // [l, r) if (q == 0) { mint ans = tree.query(l, r).a * k; cout << ans << endl; } else if (q == 1) { // (p,q,r)=(0,0,k) tree.update(l, r, Lz::Q{ 0,0,k }); } else if (q == 2) { tree.update(l, r, Lz::Q{ 1,0,k }); } else if (q == 3) { tree.update(l, r, Lz::Q{ k,0,0 }); } else { // q==4 tree.update(l, r, Lz::Q{ 1,k,0 }); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }