#line 1 "b.cpp" #include using namespace std; using ll=long long; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using pq_ = priority_queue, greater>; template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(int)(a&1),a>>=1;}return res;} template T square(T a){return a * a;} #include struct lazy_S { int a = 0; int b = 0; }; using lazy_F = int; lazy_S lazy_op(lazy_S l, lazy_S r) { return {l.a + r.a, l.b + r.b}; } lazy_S lazy_e() { return lazy_S{}; } lazy_S mapping(lazy_F l, lazy_S r) { if (l) swap(r.a, r.b); return r; } //l(r(x)) lazy_F composition(lazy_F l, lazy_F r) { return l ^ r; } lazy_F lazy_id(){return 0;} bool f(lazy_S a) { return a.b == 0; } #define lazy_calc lazy_S,lazy_op,lazy_e,lazy_F,mapping,composition,lazy_id lazy_S lazy_op2(lazy_S l, lazy_S r) { return {l.a + r.a, l.b + r.b}; } lazy_S lazy_e2() { return lazy_S{}; } lazy_S mapping2(lazy_F l, lazy_S r) { r.a += r.b * l; return r; } //l(r(x)) lazy_F composition2(lazy_F l, lazy_F r) { return l + r; } lazy_F lazy_id2(){return 0;} #line 3 "/Users/Shared/po167_library/fps/FPS_Product_Sequence.hpp" #include namespace po167{ template std::vector FPS_Product_Sequence(std::vector> f){ if (f.empty()) return {1}; auto op = [&](auto self,int l, int r) -> std::vector { if (l + 1 == r) return f[l]; int m = (l + r) / 2; return atcoder::convolution(self(self, l, m), self(self, m, r)); }; return op(op, 0, f.size()); } } #line 79 "b.cpp" using mint = atcoder::modint998244353; void solve(); // DEAR MYSTERIES / TOMOO int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ int N, Q; cin >> N >> Q; vector base_seg(N); { string S; cin >> S; rep(i, 0, N){ if (S[i] == 'G'){ base_seg[i].a = 1; } else{ base_seg[i].b = 1; } } } atcoder::lazy_segtree seg(base_seg); atcoder::lazy_segtree segW(N + 1); rep(i, 0, N + 1){ int w; cin >> w; segW.set(i, {w, 1}); } while (Q--){ int t; cin >> t; if (t == 1){ int l, r; cin >> l >> r; seg.apply(l - 1, r , 1); } if (t == 2){ int l, r, a; cin >> l >> r >> a; segW.apply(l, r + 1, a); } if (t == 3){ int u, K; cin >> u >> K; vector v(K); rep(i, 0, K) cin >> v[i]; // mv に移動した直後に、移動がある int mv = seg.max_right(u) + 1; vector> pro; int ind = 0; while (ind != K && v[ind] <= mv){ if (u <= v[ind]) pro.push_back({0, 1}); ind++; } // cout << mv << " " << ind << endl; mint ng = segW.prod(0, mv + 1).a; mint ok = segW.prod(u, mv + 1).a; // cerr << ng.val() << " " << ok.val() << "\n"; { ng -= ok; mint sum = (ng + ok).inv(); ng *= sum; ok *= sum; } // B の index の集合を -2, b1, ... bk, N // [b[i] + 2, b[i + 1] + 2) が同じグループ // v[i], v[i + 1] が同じ // -> S[v[i] - 1, ... , v[i + 1] - 1) が全て G for (int l = ind, r = ind; r < K; l = r){ while (r != K && seg.prod(v[l] - 1, v[r] - 1).b == 0){ r++; } vector tmp(r - l + 1); tmp[0] = ng; tmp[r - l] = ok; pro.push_back(tmp); } vector ans; if (!pro.empty()) ans = po167::FPS_Product_Sequence(pro); ans.resize(K + 1); rep(i, 0, K + 1) cout << ans[i].val() << (i == K ? "\n" : " "); } } }