結果

問題 No.2215 Slide Subset Sum
ユーザー ぷらぷら
提出日時 2023-02-10 22:55:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,010 bytes
コンパイル時間 6,561 ms
コンパイル使用メモリ 272,276 KB
実行使用メモリ 184,128 KB
最終ジャッジ日時 2023-09-22 00:03:56
合計ジャッジ時間 13,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 706 ms
40,188 KB
testcase_01 AC 2,512 ms
179,300 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

constexpr int mod = 998244353;

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

template <typename T>
struct SegmentTree {
    int n,kk;
    vector<T> dat;
    SegmentTree() {}
    SegmentTree(int N,int K,vector<int>A) {
        n = 1;
        while(n < N) {
            n *= 2;
        }
        kk = K;
        dat.resize(2*n-1);
        for(int i = 0; i < N; i++) {
            vector<int>tmp(K);
            tmp[A[i]] = 1;
            tmp[0]++;
            dat[n-1+i] = tmp;
        }
        for(int i = n-2; i >= 0; i--) {
            if(dat[i*2+2].size() == 0) {
                dat[i] = dat[i*2+1];
                continue;
            }
            if(dat[i*2+1].size() == 0) {
                dat[i] = dat[i*2+2];
                continue;
            }
            vector<int>res = convolution(dat[i*2+1],dat[i*2+2]);
            for(int j = K; j < res.size(); j++) {
                mpl(res[j-K],res[j]);
            }
            res.resize(K);
            dat[i] = res;
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return {};
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        if(vr.size() == 0) return vl;
        if(vl.size() == 0) return vr;
        vector<int>nxt = convolution(vl,vr);
        for(int j = kk; j < nxt.size(); j++) {
            mpl(nxt[j-kk],nxt[j]);
        }
        nxt.resize(kk);
        return nxt;
    }
    T query(int a,int b) {//[a,b)
        return query(a,b,0,0,n);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    SegmentTree<vector<int>>Seg(N,K,A);
    for(int i = 0; i+M <= N; i++) {
        cout << (Seg.query(i,i+M)[0]+mod-1)%mod << endl;
    }
}
0