結果

問題 No.3439 [Cherry 8th Tune] どの頂点にいた頃に戻りたいのか?
コンテスト
ユーザー 👑 potato167
提出日時 2026-01-23 22:43:41
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 5,718 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,911 ms
コンパイル使用メモリ 278,152 KB
実行使用メモリ 25,240 KB
最終ジャッジ日時 2026-01-23 22:45:51
合計ジャッジ時間 19,387 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#line 1 "b.cpp"
#include <bits/stdc++.h>
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<class T> using pq_ = priority_queue<T, vector<T>, greater<T>>;
template<class T> int LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> int UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &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<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &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<class T> T square(T a){return a * a;}

#include <atcoder/lazysegtree>


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 <atcoder/convolution>

namespace po167{
template<class T>
std::vector<T> FPS_Product_Sequence(std::vector<std::vector<T>> f){
    if (f.empty()) return {1};
    auto op = [&](auto self,int l, int r) -> std::vector<T> {
        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<lazy_S> 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<lazy_calc> seg(base_seg);
    atcoder::lazy_segtree<lazy_S,lazy_op2,lazy_e2,lazy_F,mapping2,composition2,lazy_id2> 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<int> v(K);
            rep(i, 0, K) cin >> v[i];
            // mv に移動した直後に、移動がある
            int mv = seg.max_right<f>(max(0, u - 1)) + 1;
            vector<vector<mint>> pro;
            int ind = 0;
            while (ind != K && v[ind] <= mv){
                if (u <= v[ind]) pro.push_back({0, 1});
                ind++;
            }
            // cout << mv << " " << ind << endl;
            if (ind != K) {
                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<mint> tmp(r - l + 1);
                    tmp[0] = ng;
                    tmp[r - l] = ok;
                    pro.push_back(tmp);
                }
            }
            vector<mint> 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" : " ");
        }
    }
}
0