Submission #957508

#TimeUsernameProblemLanguageResultExecution timeMemory
957508PringSprinkler (JOI22_sprinkler)C++17
100 / 100
746 ms102152 KiB
#include <bits/stdc++.h> using namespace std; #ifdef MIKU string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m"; #define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x) void dout() { cout << dbrs << endl; } template <typename T, typename ...U> void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); } #else #define debug(...) 39 #endif #define int long long #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) typedef pair<int, int> pii; const int MXN = 200005, MXC = 45; int n, q, mod, h[MXN]; vector<int> edge[MXN + MXC]; int p[MXN + MXC]; int drawer[MXN + MXC][MXC]; void ADD_EDGE(int x, int y) { edge[x].push_back(y); edge[y].push_back(x); } void DFS(int id, int par) { p[id] = par; for (auto &i : edge[id]) { if (i == par) continue; DFS(i, id); } } void PRE() { ADD_EDGE(1, n + 1); FOR(i, n + 1, n + MXC) ADD_EDGE(i, i + 1); DFS(n + MXC, 0); FOR(i, 1, n + MXC + 1) fill(drawer[i], drawer[i] + MXC, 1); } void MODIFY(int id, int d, int v) { auto PUT = [&](int id, int slot, int val) -> void { if (slot < 0) return; drawer[id][slot] = drawer[id][slot] * val % mod; }; int now = id; FOR(i, 0, MXC) { PUT(now, d - i, v); PUT(now, d - i - 1, v); now = p[now]; } } int QUERY(int id) { int ans = h[id], now = id; FOR(i, 0, MXC) { ans = ans * drawer[now][i] % mod; now = p[now]; } return ans; } void miku() { int x, y; cin >> n >> mod; FOR(i, 1, n) { cin >> x >> y; ADD_EDGE(x, y); } FOR(i, 1, n + 1) cin >> h[i]; PRE(); cin >> q; while (q--) { int t, x, d, v; cin >> t; if (t == 1) { cin >> x >> d >> v; MODIFY(x, d, v); } else { cin >> x; cout << QUERY(x) << '\n'; } } } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); miku(); return 0; }
#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...