1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| #include <bits/stdc++.h>
#define x first #define y second #define y1 Y1 #define y2 Y2 #define mp make_pair #define pb push_back
using namespace std;
typedef long long LL; typedef pair <int, int> pii;
template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> inline T read () { T sum = 0, fl = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1; for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0'; return sum * fl; }
inline void proc_status () { ifstream t ("/proc/self/status"); cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl; }
const int Maxn = 1e5 + 100; const int Mod = 998244353;
inline void Add (int &a, int b) { if ((a += b) >= Mod) a -= Mod; } inline void Mul (int &a, int b) { a = (LL) a * b % Mod; }
int N, M, ans;
namespace SEG { #define mid ((l + r) >> 1) #define ls root << 1 #define rs root << 1 | 1 #define lson ls, l, mid #define rson rs, mid + 1, r
struct info { int val, val_mul; int f, f_add, f_mul; } node[Maxn << 2];
inline void build (int root, int l, int r) { node[root].val_mul = node[root].f_mul = 1; if (l == r) return ; else build (lson), build (rson); }
inline void push_val_mul (int root, int x) { Mul (node[root].val, x); Mul (node[root].val_mul, x); }
inline void push_f_add (int root, int x) { Add (node[root].f, x); Add (node[root].f_add, x); }
inline void push_f_mul (int root, int x) { Mul (node[root].f, x); Mul (node[root].f_mul, x); Mul (node[root].f_add, x); }
inline void push_down (int root) { if (node[root].val_mul != 1) { push_val_mul (ls, node[root].val_mul), push_val_mul (rs, node[root].val_mul); node[root].val_mul = 1; }
if (node[root].f_mul != 1) { push_f_mul (ls, node[root].f_mul), push_f_mul (rs, node[root].f_mul); node[root].f_mul = 1; }
if (node[root].f_add) { push_f_add (ls, node[root].f_add), push_f_add (rs, node[root].f_add); node[root].f_add = 0; } }
inline int update (int root, int l, int r, int x, int y, int pow2) { if (r < x || y < l) { Add (ans, Mod - node[root].val); Add (node[root].val, node[root].f); push_f_mul (root, 2); Mul (node[root].val_mul, 2);
return node[root].val; }
if (x <= l && r <= y) { Add (ans, Mod - node[root].val);
Add (node[root].val, pow2); push_f_add (root, pow2); Mul (node[root].val_mul, 2);
return node[root].val; }
push_down (root); int sum = node[root].val; Add (ans, Mod - node[root].val); Add (sum, update (lson, x, y, pow2)); Add (sum, update (rson, x, y, pow2)); return sum; }
#undef mid #undef ls #undef rs #undef lson #undef rson }
inline void Solve () { SEG :: build (1, 1, N); int sum = 1; while (M--) { int op = read<int>(); if (op == 1) { int l = read<int>(), r = read<int>();
int now_ans = SEG :: update (1, 1, N, l, r, sum);
ans = (2ll * ans % Mod + now_ans) % Mod; sum = (LL) sum * 2 % Mod; } else printf("%d\n", ans); } }
inline void Input () { N = read<int>(), M = read<int>(); }
int main() {
#ifndef ONLINE_JUDGE freopen("A.in", "r", stdin); freopen("A.out", "w", stdout); #endif
Input (); Solve ();
return 0; }
|