using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using E = System.Linq.Enumerable; partial class Solver { const int Mod = 1000000007; public struct Monoid { public long Value; public long F; } public struct MonoidOperator { public long Add; public long Mul; public long AddF; } public class LazySegmentTreeMonoidOperator : ILazySegmentTreeMonoidOperator { public Monoid Apply(MonoidOperator operation, Monoid monoid, int dataNum) { return new Monoid { Value = (monoid.Value * operation.Mul + monoid.F * operation.AddF + dataNum * operation.Add) % Mod, F = monoid.F, }; } public Monoid Merge(ref Monoid left, ref Monoid right) { return new Monoid { Value = (left.Value + right.Value) % Mod, F = (left.F + right.F) % Mod, }; } // (monoid.Value * operation.Mul + monoid.F * operation.AddF + dataNum * operation.Add) // (monoid.Value * operation.Mul + monoid.F * operation.AddF + dataNum * operation.Add) * operation2.Mul + monoid.F * operation2.AddF + dataNum * operation2.Add) // monoid.Value * operation.Mul * operation2.Mul + monoid.F * operation.AddF * operation2.Mul + dataNum * operation.Add * operation2.Mul + monoid.F * operation2.AddF + dataNum * operation2.Add // monoid.Value * operation.Mul * operation2.Mul // + monoid.F * operation.AddF * operation2.Mul + monoid.F * operation2.AddF // + dataNum * operation.Add * operation2.Mul + dataNum * operation2.Add // monoid.Value * operation.Mul * operation2.Mul // + monoid.F * (operation.AddF * operation2.Mul +operation2.AddF) // + dataNum * (operation.Add * operation2.Mul * operation2.Add) public MonoidOperator MergeOperator(MonoidOperator left, MonoidOperator right) { return new MonoidOperator { Add = (left.Add * right.Mul + right.Add) % Mod, Mul = (left.Mul * right.Mul) % Mod, AddF = (left.AddF * right.Mul + right.AddF) % Mod, }; } } public void Run() { var N = ni(); var Q = ni(); var tree = new LazySegmentTreeMonoidOperator().Create(); var f = new long[N + 2]; f[0] = 0; f[1] = 1; for (int i = 2; i < N; i++) f[i] = (f[i - 1] + f[i - 2]) % Mod; tree.Build(N, i => new Monoid { F = f[i] }); for (int i = 0; i < Q; i++) { var q = ni(); var l = ni(); var r = ni(); var k = ni(); switch (q) { case 0: cout.WriteLine(tree.Query(l, r + 1).Value * k % Mod); break; case 1: tree.LazyUpdate(l, r + 1, new MonoidOperator { Add = k, Mul = 0, AddF = 0 }); break; case 2: tree.LazyUpdate(l, r + 1, new MonoidOperator { Add = k, Mul = 1, AddF = 0 }); break; case 3: tree.LazyUpdate(l, r + 1, new MonoidOperator { Add = 0, Mul = k, AddF = 0 }); break; case 4: tree.LazyUpdate(l, r + 1, new MonoidOperator { Add = 0, Mul = 1, AddF = k }); break; } } } } public interface ILazySegmentTreeMonoidOperator where TMonoid : struct where TOperatorMonoid : struct { TMonoid Merge(ref TMonoid left, ref TMonoid right); TOperatorMonoid MergeOperator(TOperatorMonoid left, TOperatorMonoid right); TMonoid Apply(TOperatorMonoid operation, TMonoid monoid, int dataNum); } public static class OperatorLazySegmentTreeExtension { static public OperatorLazySegmentTree Create (this ILazySegmentTreeMonoidOperator lazySegmentTreeMonoidOperator) where TMonoid : struct where TOperatorMonoid : struct { return new OperatorLazySegmentTree(lazySegmentTreeMonoidOperator); } } public abstract class SegmentTree where TMonoid : struct { protected int N { get; private set; } protected TMonoid?[] node; protected static int Left(int p) { return p * 2 + 1; } protected static int Right(int p) { return p * 2 + 2; } public SegmentTree() { } public void Build(IList array) { Build(array.Count, i => array[i]); } virtual public void Build(int _n, Func create) { N = 1; while (N < _n) N *= 2; node = new TMonoid?[2 * N]; for (int i = 0; i < _n; i++) node[i + N - 1] = create(i); for (int i = N - 2; i >= 0; i--) node[i] = Merge(node[Left(i)], node[Right(i)]); } protected TMonoid? Merge(TMonoid? left, TMonoid? right) { if (left != null && right != null) return Merge(left.Value, right.Value); if (left == null) return right; if (right == null) return left; return null; } protected abstract TMonoid Merge(TMonoid left, TMonoid right); public void Update(int index, TMonoid val) { int p = index + N - 1; node[p] = val; while (p > 0) { p = (p - 1) / 2; node[p] = Merge(node[Left(p)], node[Right(p)]); } } protected virtual TMonoid? Query(int begin, int end, int k, int l, int r) { if (r <= begin || end <= l) return null; if (begin <= l && r <= end) return node[k]; int mid = (l + r) / 2; return Merge( Query(begin, end, Left(k), l, mid), Query(begin, end, Right(k), mid, r) ); } public TMonoid Query(int begin, int end) { return Query(begin, end, 0, 0, N).Value; } }; public class OperatorLazySegmentTree : SegmentTree where TMonoid : struct where TOperatorMonoid : struct { readonly ILazySegmentTreeMonoidOperator monoidOperator; private TOperatorMonoid?[] operators; public OperatorLazySegmentTree(ILazySegmentTreeMonoidOperator lazySegmentTreeMonoidOperator) { monoidOperator = lazySegmentTreeMonoidOperator; } public override void Build(int _n, Func create) { base.Build(_n, create); operators = new TOperatorMonoid?[2 * N]; } protected override TMonoid Merge(TMonoid left, TMonoid right) { return monoidOperator.Merge(ref left, ref right); } protected TOperatorMonoid? MergeOperator(TOperatorMonoid? left, TOperatorMonoid? right) { if (left.HasValue && right.HasValue) return monoidOperator.MergeOperator(left.Value, right.Value); return left ?? right; } protected void LazyPropagate(int k, int l, int r) { if (!operators[k].HasValue) return; if (k < N - 1) { int childL = Left(k), childR = Right(k); operators[childL] = MergeOperator(operators[childL], operators[k]); operators[childR] = MergeOperator(operators[childR], operators[k]); } node[k] = monoidOperator.Apply(operators[k].Value, node[k].Value, r - l); operators[k] = null; } protected override TMonoid? Query(int begin, int end, int k, int l, int r) { LazyPropagate(k, l, r); return base.Query(begin, end, k, l, r); } private void LazyUpdate( int begin, int end, TOperatorMonoid @operator, int k, int l, int r) { if (r <= begin || end <= l) { LazyPropagate(k, l, r); return; } if (begin <= l && r <= end) { operators[k] = MergeOperator(operators[k], @operator); LazyPropagate(k, l, r); return; } LazyPropagate(k, l, r); int mid = (l + r) / 2; LazyUpdate(begin, end, @operator, Left(k), l, mid); LazyUpdate(begin, end, @operator, Right(k), mid, r); node[k] = Merge(node[Left(k)], node[Right(k)]); } public void LazyUpdate(int begin, int end, TOperatorMonoid @operator) { LazyUpdate(begin, end, @operator, 0, 0, N); } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL new Solver(Console.In, Console.Out).Run(); #else Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { this.cin = reader; this.cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) { } #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } public class Scanner { private readonly TextReader Reader; private readonly Queue TokenQueue = new Queue(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) { } public Scanner(TextReader reader) { this.Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); return array; } public double[] NextDoubleArray(int size) { var array = new double[size]; for (int i = 0; i < size; i++) array[i] = NextDouble(); return array; } public string Next() { if (TokenQueue.Count == 0) { if (!StockTokens()) throw new InvalidOperationException(); } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) return true; return StockTokens(); } static readonly char[] _separator = new[] { ' ' }; private bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }