結果
問題 | No.623 fudan no modulus to tigau |
ユーザー |
👑 |
提出日時 | 2019-05-06 11:35:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 717 ms |
コンパイル使用メモリ | 77,168 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 06:35:51 |
合計ジャッジ時間 | 1,420 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#include <cstdio>#include <cstdlib>#include <cstddef>#include <vector>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <iostream>#include <iomanip>#include <numeric>#define L64 long long#define MOD (998244353LL)int main(void){int n;std::cin >> n;std::vector<int> t(n + 1);std::vector<int> a(n + 1);std::vector<int> b(n + 1);for (int i = 2; i <= n; i++){std::cin >> t[i] >> a[i] >> b[i];}int q; std::cin >> q;for (int i_q = 1; i_q <= q; i_q++){L64 x; std::cin >> x;std::vector<L64> f(n + 1);f[0] = 1; f[1] = x;for (int i_n = 2; i_n <= n; i_n++){switch(t[i_n]){case 1:f[i_n] = (f[a[i_n]] + f[b[i_n]]) % MOD;break;case 2:f[i_n] = ((L64)a[i_n] * f[b[i_n]]) % MOD;break;case 3:f[i_n] = (f[a[i_n]] * f[b[i_n]]) % MOD;break;}}std::cout << f[n] << std::endl;}}