#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; #include using Modint = atcoder::static_modint<998244353>; #include #include #include #include template struct vec; template struct seq_view{ using Ref = typename std::iterator_traits::reference; using Elem = typename std::iterator_traits::value_type; Iter a, b; Iter begin() const { return a; } Iter end() const { return b; } int size() const { return (int)(b-a); } seq_view(Iter first, Iter last) : a(first), b(last) {} seq_view sort() const { std::sort(a, b); return *this; } Ref& operator[](int x) const { return *(a+x); } template, class ret = vec> ret sorti(F f = F()) const { ret x(size()); for(int i=0; i> ret col() const { return ret(begin(), end()); } template> ret cumsum() const { auto res = ret(size() + 1, Elem(0)); for(int i=0; i, class ret = vec>> ret rle(F eq = F()) const { auto x = ret(); for(auto& a : (*this)){ if(x.size() == 0 || !eq(x[x.size()-1].first, a)) x.emp(a, 1); else x[x.size()-1].second++; } return x; } template seq_view sort(F f) const { std::sort(a, b, f); return *this; } Iter uni() const { return std::unique(a, b); } Iter lb(const Elem& x) const { return std::lower_bound(a, b, x); } Iter ub(const Elem& x) const { return std::upper_bound(a, b, x); } int lbi(const Elem& x) const { return lb(x) - a; } int ubi(const Elem& x) const { return ub(x) - a; } seq_view bound(const Elem& l, const Elem& r) const { return { lb(l), lb(r) }; } template Iter lb(const Elem& x, F f) const { return std::lower_bound(a, b, x, f); } template Iter ub(const Elem& x, F f) const { return std::upper_bound(a, b, x, f); } template Iter when_true_to_false(F f) const { if(a == b) return a; return std::lower_bound(a, b, *a, [&](const Elem& x, const Elem&){ return f(x); }); } seq_view same(Elem x) const { return { lb(x), ub(x) }; } template auto map(F f) const { vec()))> r; for(auto& x : *this) r.emp(f(x)); return r; } Iter max() const { return std::max_element(a, b); } Iter min() const { return std::min_element(a, b); } template> Iter min(F f) const { return std::min_element(a, b, f); } seq_view rev() const { std::reverse(a, b); return *this; } }; template struct vec { public: using Base = typename std::vector; using Iter = typename Base::iterator; using CIter = typename Base::const_iterator; using View = seq_view; using CView = seq_view; vec(){} explicit vec(int n, const Elem& value = Elem()) : a(0 vec(I2 first, I2 last) : a(first, last) {} vec(std::initializer_list il) : a(std::move(il)) {} vec(Base b) : a(std::move(b)) {} operator Base() const { return a; } Iter begin(){ return a.begin(); } CIter begin() const { return a.begin(); } Iter end(){ return a.end(); } CIter end() const { return a.end(); } int size() const { return a.size(); } bool empty() const { return a.empty(); } Elem& back(){ return a.back(); } const Elem& back() const { return a.back(); } vec& sortuni(){ (*this)().sort(); a.erase((*this)().uni(), end()); return *this; } vec sortunied(){ vec x = *this; x.sortuni(); return x; } Iter operator()(int x){ return a.begin() + x; } CIter operator()(int x) const { return a.begin() + x; } View operator()(int l, int r){ return { (*this)(l), (*this)(r) }; } CView operator()(int l, int r) const { return { (*this)(l), (*this)(r) }; } View operator()(){ return (*this)(0,size()); } CView operator()() const { return (*this)(0,size()); } Elem& operator[](int x){ return a[x]; } const Elem& operator[](int x) const { return a[x]; } Base& operator*(){ return a; } const Base& operator*() const { return a; } vec& push(Elem args){ a.push_back(std::move(args)); return *this; } template vec& emp(Args &&... args){ a.emplace_back(std::forward(args) ...); return *this; } template vec& app(Range& x){ for(auto& v : x){ emp(v); } return *this; } Elem pop(){ Elem x = std::move(a.back()); a.pop_back(); return x; } void resize(int sz){ a.resize(sz); } void reserve(int sz){ a.reserve(sz); } bool operator==(const vec& r) const { return a == r.a; } bool operator!=(const vec& r) const { return a != r.a; } bool operator<(const vec& r) const { return a < r.a; } bool operator<=(const vec& r) const { return a <= r.a; } bool operator>(const vec& r) const { return a > r.a; } bool operator>=(const vec& r) const { return a >= r.a; } vec> pile(int n) const { return vec>(n, *this); } template vec& filter(F f){ int p = 0; for(auto& x : a) if(f(x)) std::swap(a[p++],x); resize(p); return *this; } vec& operator+=(const vec& r){ return app(r); } vec operator+(const vec& r) const { vec x = *this; x += r; return x; } vec operator*(int t) const { vec res; while(t--){ res += *this; } return res; } private: Base a; }; template IStr& operator>>(IStr& is, vec>& v){ for(auto& x:v){ is >> x.first >> x.second; } return is; } template IStr& operator>>(IStr& is, vec& v){ for(auto& x:v){ is >> x; } return is; } template OStr& operator<<(OStr& os, const vec& v){ for(int i=0; i OStr& operator<<(OStr& os, const vec>& v){ for(int i=0; i& a, i64 i){ i64 I = 1 << i; rep(j,1<& a, vec& b){ rep(j,1<& a, i64 i){ i64 I = 1 << i; rep(j,1<& a, i64 i){ i64 I = 1 << i; rep(j,1< subx(i64 N, vec F, vec G){ //cout << "subx(" << N << ")" << endl; //cout << " F : "; rep(i,1< res(1< sub(i64 N, vec A, vec CA, vec B, vec CB){ // cout << "sub(" << N << ")" << endl; // cout << " A = " << A << endl; // cout << " CA = "; for(auto a : CA){ cout << a.val() << " "; } cout << endl; // cout << " B = " << B << endl; // cout << " CB = "; for(auto a : CB){ cout << a.val() << " "; } cout << endl; i64 M = A.size(); rep(i,M) B[i] ^= A[i]; i64 NN = 1 << N; vec F(NN, 1); vec G(NN, 0); rep(i,M){ i64 b = B[i]; Modint p = F[b] * CA[i] + G[b] * CB[i]; Modint q = F[b] * CB[i] + G[b] * CA[i]; F[b] = p; G[b] = q; } auto res = subx(N, move(F), move(G)); vec ans(1<> N >> M; vec L(M), R(M); rep(i,M){ cin >> L[i] >> R[i]; R[i]++; } auto solve = [&](auto& solve, i64 b) -> vec { //cout << "solve(" << b << ")" << endl; if(b == N){ Modint q = 1; rep(i,M) q *= R[i] - L[i]; return vec(1, q); } auto rough = solve(solve, b+1); vec A(M), B(M); vec CA(M), CB(M); rep(i,M){ if((L[i] >> b) == ((R[i]-1) >> b)){ A[i] = (L[i] >> b); CA[i] = R[i] - L[i]; B[i] = (L[i] >> b); CB[i] = 0; } else { if((L[i] >> b) & 1){ A[i] = (L[i] >> b); CA[i] = L[i] - ((A[i] + 1) << b); } else { A[i] = (L[i] >> b); CA[i] = L[i] - (A[i] << b); } if(((R[i]-1) >> b) & 1){ B[i] = ((R[i]-1) >> b); CB[i] = ((B[i] + 1) << b) - R[i]; } else { B[i] = ((R[i]-1) >> b); CB[i] = (B[i] << b) - R[i]; } } } auto diff = sub(N-b, move(A), move(CA), move(B), move(CB)); vec res(1<<(N-b)); Modint inv2 = Modint(2).inv(); rep(i,1<<(N-b-1)){ res[i*2+0] = (rough[i] + diff[i*2+0] - diff[i*2+1]) * inv2; res[i*2+1] = (rough[i] + diff[i*2+1] - diff[i*2+0]) * inv2; } //cout << "return solve(" << b << ")" << endl; //cout << " X : "; rep(i,1<<(N-b)){ cout << res[i].val() << " "; } cout << endl; return res; }; auto ans = solve(solve, 0); rep(i,1<