import sys def popcount(n): c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F) c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF) c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF) c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF) return c class DualSegTree: def __init__(self, n, comp, id): self.n = n self.comp = comp self.id = id self.sz = 1 self.log = 0 while self.sz < n: self.sz <<= 1 self.log += 1 self.lz = [id] * (self.sz * 2) def push(self, p): self.lz[p << 1] = self.comp(self.lz[p], self.lz[p << 1]) self.lz[(p << 1) + 1] = self.comp(self.lz[p], self.lz[(p << 1) + 1]) self.lz[p] = self.id def push_all(self, p): for i in range(self.log, 0, -1): self.push(p >> i) def get(self, p): P = p + self.sz self.push_all(P) return self.lz[P] def set(self, p, f): P = p + self.sz self.push_all(P) self.lz[P] = f def apply(self, l, r, f): if l >= r: return L = l + self.sz R = r + self.sz for i in range(self.log, 0, -1): if ((L >> i) << i) != L: self.push(L >> i) if ((R >> i) << i) != R: self.push((R - 1) >> i) while L < R: if L & 1: self.lz[L] = self.comp(f, self.lz[L]) L += 1 if R & 1: R -= 1 self.lz[R] = self.comp(f, self.lz[R]) L >>= 1 R >>= 1 LOG = 30 MASK = (1 << LOG) - 1 MOD = 998244353 def comp(f, g): return ((~g[0] & f[0]) | (g[0] & f[1]), (~g[1] & f[0]) | (g[1] & f[1])) id = (0, MASK) s = input().split(" ") n = int(s[0]) q = int(s[1]) m = list(map(int, input().split())) seg = DualSegTree(n, comp, id) for i in range(q): s = input().split(" ") l = int(s[1]) - 1 r = int(s[2]) x = int(s[3]) seg.apply(l, r, (x, MASK if s[0] == "o" else MASK ^ x)) fact = [1] * 100 ifact = [1] * 100 for i in range(1, 100): fact[i] = fact[i - 1] * i % MOD ifact[99] = pow(fact[99], MOD - 2, MOD) for i in range(99, 0, -1): ifact[i - 1] = ifact[i] * i % MOD def binom(n, k): return 0 if k < 0 or k > n else fact[n] * ifact[k] % MOD * ifact[n - k] % MOD prod = [1] * (LOG + 1) for p in range(n): r = seg.get(p) b = r[0] c = r[1] ma = m[p] + 1 f = [0] * (LOG + 1) cnt = [0, 0, 0] a = popcount(((ma ^ MASK) & b) | (ma & c)) for i in range(LOG): a -= (((ma ^ MASK) & b) | (ma & c)) & 1 a += b & 1 if ma & 1: for j in range(LOG + 1): f[j] += binom(cnt[1], j - a - cnt[2]) * (1 << (cnt[0] + cnt[2])) % MOD a -= b & 1 cnt[(b & 1) + (c & 1)] += 1 ma >>= 1 b >>= 1 c >>= 1 for i in range(LOG): f[i + 1] += f[i] if f[i + 1] >= MOD: f[i + 1] -= MOD for i in range(LOG + 1): prod[i] = prod[i] * f[i] % MOD ans = LOG * prod[LOG] % MOD for i in range(LOG): ans -= prod[i] if ans < 0: ans += MOD print(ans)