| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1283502 | quangminh412 | Sprinkler (JOI22_sprinkler) | C++17 | 534 ms | 52024 KiB | 
/*
  Ben Watson
  Quang Minh MasterDDDDD
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const string name = "test";
void solve();
signed main()
{
    if (fopen((name + ".inp").c_str(), "r"))
    {
        freopen((name + ".inp").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}
// main program
const int maxn = 2e5 + 1;
const int maxd = 41;
int mod;
int mul(int a, int b) { return 1ll * a * b % mod; }
vector<int> adj[maxn];
int val[maxd][maxn], par[maxn];
int n, q;
void DFS(int u, int p = -1)
{
    for (int v : adj[u])
    {
        if (v == p)
            continue;
        par[v] = u;
        DFS(v, u);
    }
}
void solve()
{
    cin >> n >> mod;
    for (int i = 1; i < n; i++)
    {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i = 0; i < maxd; i++)
        for (int j = 0; j <= n; j++)
            val[i][j] = 1;
    for (int i = 1; i <= n; i++)
        cin >> val[0][i];
    DFS(1);
    cin >> q;
    while (q--)
    {
        int type; cin >> type;
        if (type == 1)
        {
            int x, d, w; cin >> x >> d >> w;
            while (1)
            {
                val[d][x] = mul(val[d][x], w);
                if (d-- == 0)
                    break;
                val[d][x] = mul(val[d][x], w);
                if (x != 1)
                    x = par[x];
                else
                if (d-- == 0)
                    break;
            }
        } else
        {
            int x; cin >> x;
            int res = 1;
            for (int d = 0; d < maxd && 1 <= x; d++, x = par[x])
                res = mul(res, val[d][x]);
            cout << res << '\n';
        }
    }
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
