#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; } struct P { mint a, f, c; }; const P EP = P{ 0,0,1 }; struct Q { mint p, q, r; }; bool operator==(Q qa, Q qb) { return qa.p.toi() == qb.p.toi() &&qa.q.toi() == qb.q.toi() &&qa.r.toi() == qb.r.toi(); } const Q EQ = Q{ 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 }; } // qaのあとにqb 適用 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) { dataSize = 1; while (dataSize < n)dataSize *= 2; int treeSize = 2 * dataSize; value = vector

(treeSize, EP); lazy = vector(treeSize, EQ); // value = lazy = vector(treeSize); } LazySegTree(vector

dat) { dataSize = 1; int n = (int)dat.size(); while (dataSize < n)dataSize *= 2; int treeSize = 2 * dataSize; value = vector

(treeSize, EP); lazy = vector(treeSize, EQ); for (int i = 0; i < n; ++i) { value[dataSize+i] = dat[i]; } for (int i = dataSize - 1; i >= 0; --i) { value[i] = f(value[i * 2], value[i * 2 + 1]); } } void propagate(int index, int curL, int curR) { // 自分の値をlazyにもとづいて書き換えて自分のlazyをクリア。 if (!(lazy[index]==EQ)) { int left = index * 2, right = index * 2 + 1; value[index] = g(value[index], lazy[index]); // 子のlazyを書き換える。 if (curR - curL > 1) { lazy[left] = h(lazy[left], lazy[index]); lazy[right] = h(lazy[right], lazy[index]); } lazy[index] = EQ; } } // [curL, curR) を評価する void update(int index, int curL, int curR, int givenL, int givenR, Q x) { // 範囲外であろうとpropagateは必ず呼ぶ。そうでないと、親がうまく評価されない propagate(index, curL, curR); // 範囲外 if (curR <= givenL || givenR <= curL)return; if (givenL <= curL && curR <= givenR) { // 直接書き換えないでindexのlazyを書き換えてpropagateを呼ぶ lazy[index] = 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] = f(value[index * 2], value[index * 2 + 1]); } } void update(int l, int r, Q x) { update(1, 0, dataSize, l, r, x); } P query(int l, int r) { return query(1, 0, dataSize, l, r); } P query(int index, int curL, int curR, int givenL, int givenR) { // 範囲外 if (curR <= givenL || givenR <= curL)return EP; propagate(index, curL, curR); if (givenL <= curL && curR <= givenR) { return value[index]; } else { int mid = (curL + curR) / 2; P resL = query(index * 2, curL, mid, givenL, givenR); P resR = query(index * 2 + 1, mid, curR, givenL, givenR); return f(resL, resR); } } }; void solve() { int N, M; cin >> N >> M; // フィボナッチ数列は事前に計算 vector

a(N, 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) // rep(i, N)cout << tree.query(i, i + 1).a << ' '; // cout << endl; 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, Q{ 0,0,k }); } else if (q == 2) { tree.update(l, r, Q{ 1,0,k }); } else if (q == 3) { tree.update(l, r, Q{ k,0,0 }); } else { // q==4 tree.update(l, r, Q{ 1,k,0 }); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }