結果

問題 No.2369 Some Products
ユーザー milanis48663220milanis48663220
提出日時 2023-06-30 23:04:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,782 bytes
コンパイル時間 5,588 ms
コンパイル使用メモリ 195,668 KB
実行使用メモリ 9,592 KB
最終ジャッジ日時 2023-09-21 17:21:19
合計ジャッジ時間 9,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,252 KB
testcase_01 AC 1 ms
4,376 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>
#include <atcoder/convolution>
#include <atcoder/segtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

struct FPS: vector<mint>{
    using vector<mint>::vector;
    FPS inv(int deg){
        FPS ans(deg);
        ans[0] = mint(1)/(*this)[0];
        for(int d = 1; d < deg; d<<=1){
            vector<mint> f(2*d), g(2*d);
            for(int i = 0; i < min(2*d, (int)this->size()); i++) f[i] = (*this)[i];
            for(int i = 0; i < d; i++) g[i] = ans[i];
            f = atcoder::convolution(g, atcoder::convolution(g, f));
            for(int i = d; i < min(2*d, deg); i++) ans[i] = -f[i];
        }
        return ans;
    }

    void shrink() {
        while (this->size() && this->back() == mint(0)) this->pop_back();
    }

    FPS& operator*=(const FPS &r){
        if(this->empty() || r.empty()){
            this->clear();
            return *this;
        }
        auto ret = atcoder::convolution(*this, r);
        return *this = FPS(ret.begin(), ret.end());
    }

    FPS& operator+=(const FPS &r){
       if(this->size() < r.size()) this->resize(r.size());
       for(int i = 0; i < (int)r.size(); i++) (*this)[i] += r[i];
        return *this;
    }

    FPS& operator-=(const FPS &r){
       if(this->size() < r.size()) this->resize(r.size());
       for(int i = 0; i < (int)r.size(); i++) (*this)[i] -= r[i];
        return *this;
    }

    FPS operator*(const FPS &r) const { 
        return FPS(*this) *= r; 
    }

    FPS operator+(const FPS &r) const { 
        return FPS(*this) += r; 
    }

    FPS operator-(const FPS &r) const { 
        return FPS(*this) -= r; 
    }

    FPS mod_deg(int deg){
        FPS ret(deg);
        for(int i = 0; i < min(deg, (int)this->size()); i++) ret[i] = (*this)[i];
        return ret;
    }
};

FPS op(FPS x, FPS y){
    return x*y;
}

FPS e(){
    return {mint(1)};
}

using Seg = atcoder::segtree<FPS, op, e>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> p(n);
    vector<FPS> f;
    for(int i = 0; i < n; i++) {
        cin >> p[i];
        f.push_back({mint(1), mint(p[i])});
    }
    Seg seg(f);
    int q; cin >> q;
    while(q--){
        int a, b, k; cin >> a >> b >> k; a--;
        auto f = seg.prod(a, b);
        if(f.size() >= k+1){
            cout << f[k] << endl;
        }else{
            cout << 0 << endl;
        }
    }
}
0