結果

問題 No.623 fudan no modulus to tigau
コンテスト
ユーザー lowr
提出日時 2019-09-26 18:44:19
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 818µs
コード長 793 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,314 ms
コンパイル使用メモリ 216,976 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-18 00:53:32
合計ジャッジ時間 2,794 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using i64 = long long;

std::vector<i64> a, b, t, pre;
constexpr i64 mod = 998244353;

i64 rec(int i, i64 x) {
    if (i == 0) return 1;
    if (i == 1) return x;
    if (pre[i] >= 0) return pre[i];
    if (t[i] == 1) return pre[i] = (rec(a[i], x) + rec(b[i], x)) % mod;
    if (t[i] == 2) return pre[i] = a[i] * rec(b[i], x) % mod;
    return pre[i] = rec(a[i], x) * rec(b[i], x) % mod;
}

int main() {
    int n;
    std::cin >> n;
    a.resize(n + 1); b.resize(n + 1); t.resize(n + 1); pre.resize(n + 1);
    for (int i = 2; i <= n; i++) std::cin >> t[i] >> a[i] >> b[i];
    
    int q;
    std::cin >> q;
    while (q--) {
        for (auto &e : pre) e = -1;
        i64 x;
        std::cin >> x;
        std::cout << rec(n, x) << std::endl;
    }
    return 0;
}
0