#include #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pi; typedef pair pl; typedef pair ppi; typedef vector vi; typedef vector vl; typedef vector mat; typedef complex comp; void Debug() {cout << '\n'; } templatevoid Debug(FIRST arg, REST... rest){ cout<ostream& operator<<(ostream& out,const vector& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<ostream& operator<<(ostream& out,const pair& v){ out<<"("< vx; ll E[1000010], F[1000010]; struct segtree { // this is piece of shit. use BIT int n; vl sum, add, mul, fib; void init(int mx) { n = 1; while(n < mx) n *= 2; sum = vl(n * 2, 0); add = vl(n * 2, 0); mul = vl(n * 2, 1); fib = vl(n * 2, 0); } segtree(int mx = 0) { init(mx); } inline void lazy_eval(int k, int l, int r) { int m = (l + r) / 2; if(add[k] || mul[k] != 1 || fib[k]) { MUL(sum[k * 2 + 1], mul[k]); ADD(sum[k * 2 + 1], (vx[m] - vx[l] + mod) * add[k] % mod); ADD(sum[k * 2 + 1], (F[vx[m]] - F[vx[l]] + mod) * fib[k] % mod); MUL(mul[k * 2 + 1], mul[k]); MUL(add[k * 2 + 1], mul[k]); MUL(fib[k * 2 + 1], mul[k]); ADD(add[k * 2 + 1], add[k]); ADD(fib[k * 2 + 1], fib[k]); MUL(sum[k * 2 + 2], mul[k]); ADD(sum[k * 2 + 2], (vx[r] - vx[m] + mod) * add[k] % mod); ADD(sum[k * 2 + 2], (F[vx[r]] - F[vx[m]] + mod) * fib[k] % mod); MUL(mul[k * 2 + 2], mul[k]); MUL(add[k * 2 + 2], mul[k]); MUL(fib[k * 2 + 2], mul[k]); ADD(add[k * 2 + 2], add[k]); ADD(fib[k * 2 + 2], fib[k]); add[k] = 0; mul[k] = 1; fib[k] = 0; } } void addapp(int a, int b, ll s, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { ADD(sum[k], (vx[r] - vx[l] + mod) * s % mod); //here too ADD(add[k], s); } else { lazy_eval(k, l, r); addapp(a, b, s, k * 2 + 1, l, (l + r) / 2); addapp(a, b, s, k * 2 + 2, (l + r) / 2, r); sum[k] = (sum[k * 2 + 1] + sum[k * 2 + 2]) % mod; } } void mulapp(int a, int b, ll s, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { MUL(sum[k], s); //here too MUL(add[k], s); MUL(mul[k], s); MUL(fib[k], s); } else { lazy_eval(k, l, r); mulapp(a, b, s, k * 2 + 1, l, (l + r) / 2); mulapp(a, b, s, k * 2 + 2, (l + r) / 2, r); sum[k] = (sum[k * 2 + 1] + sum[k * 2 + 2]) % mod; } } void fibapp(int a, int b, ll s, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { ADD(sum[k], (F[vx[r]] - F[vx[l]] + mod) * s % mod); ADD(fib[k], s); } else { lazy_eval(k, l, r); fibapp(a, b, s, k * 2 + 1, l, (l + r) / 2); fibapp(a, b, s, k * 2 + 2, (l + r) / 2, r); sum[k] = (sum[k * 2 + 1] + sum[k * 2 + 2]) % mod; } } ll ga(int a, int b, int k, int l, int r) { if(b <= l || r <= a) return ll(); if(a <= l && r <= b) return sum[k]; else { lazy_eval(k, l, r); ll lv = ga(a, b, k * 2 + 1, l, (l + r) / 2); ll rv = ga(a, b, k * 2 + 2, (l + r) / 2, r); return lv + rv; } } void show() { vector tmp; rep(i, 0, n) tmp.push_back(get(i, i + 1)); debug(tmp); } ll get(int a, int b) { return ga(a, b, 0, 0, n); } //[a, b) void addupdate(int a, int b, ll s) { addapp(a, b, s, 0, 0, n); } //[a, b) void mulupdate(int a, int b, ll s) { mulapp(a, b, s, 0, 0, n); } //[a, b) void fibupdate(int a, int b, ll s) { fibapp(a, b, s, 0, 0, n); } //[a, b) }; int N, M; ll Q[MAX_N], L[MAX_N], R[MAX_N], K[MAX_N]; segtree seg; int fd(int a) { return lower_bound(all(vx), a) - vx.begin(); } void solve() { cin >> N >> M; E[0] = 0; E[1] = 1; rep(i, 2, N) E[i] = (E[i - 1] + E[i - 2]) % mod; rep(i, 0, N) F[i + 1] = (E[i] + F[i]) % mod; // debug(vi(F, F + N + 1)); rep(i, 0, M) { cin >> Q[i] >> L[i] >> R[i] >> K[i]; R[i]++; vx.pb(L[i]); vx.pb(R[i]); } sort(all(vx)); vx.erase(unique(all(vx)), vx.end()); seg.init(sz(vx)); rep(i, 0, M) { // seg.show(); // debug(seg.sum); // debug(seg.mul); // debug(seg.add); // debug(seg.fib); int l = fd(L[i]), r = fd(R[i]); // debug(l, r, L[i], R[i]); if(Q[i] == 0) cout << (K[i] * seg.get(l, r)) % mod << "\n"; else if(Q[i] == 1) { seg.mulupdate(l, r, 0); seg.addupdate(l, r, K[i]); } else if(Q[i] == 2) seg.addupdate(l, r, K[i]); else if(Q[i] == 3) seg.mulupdate(l, r, K[i]); else seg.fibupdate(l, r, K[i]); } } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }