Submission #785530

#TimeUsernameProblemLanguageResultExecution timeMemory
785530andecaandeciSprinkler (JOI22_sprinkler)C++17
3 / 100
4046 ms15756 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second

vector<int> adj[200005];
ll a[200005], cnt[200005], l;

void dfs1(int p, int x, int c, ll val) {
    a[x] = (a[x] * val) % l;
    if (c == 0) return;
    for (auto u : adj[x]) {
        if (u == p) continue;
        dfs1(x, u, c - 1, val);
    }
}

void dfs2(int x, int c) {
    a[x] = 0, cnt[c] = c;
    if (c == 1) return;
    for (auto u : adj[x]) {
        if (c - 1 > cnt[u]) dfs2(u, c - 1);
    }
}

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n >> l;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) cin >> a[i];
    int query;
    cin >> query;
    if (n <= 2000 and query <= 2000) {
        while (query--) {
            int type;
            cin >> type;
            if (type == 1) {
                int x, d;
                ll w;
                cin >> x >> d >> w;
                dfs1(0, x, d, w);
            }
            else {
                int x;
                cin >> x;
                cout << a[x] << "\n";
            }
        }
    }
    else {
        while (query--) {
            int type;
            cin >> type;
            if (type == 1) {
                int x, d;
                ll w;
                cin >> x >> d >> w;
                if (d + 1 > cnt[x]) dfs2(x, d + 1);
            }
            else {
                int x;
                cin >> x;
                cout << a[x] << "\n";
            }
        }
    }
}  
/*
4 7
1 2
2 3
3 4
1
1
1
1
3
1 2 1 2
1 1 0 2
2 1
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...