Submission #588807

#TimeUsernameProblemLanguageResultExecution timeMemory
588807SeDunionSprinkler (JOI22_sprinkler)C++17
0 / 100
672 ms99484 KiB
#include<iostream> #include<vector> using namespace std; using ll = long long; const int N = 5e5 + 123; const int LOG = 20; const int D = 45; ll h[N], q[N][D]; int n, L; void mult(ll &a, ll b) { a += b; return; a *= b; a %= L; } void dvdv(ll &a, ll b) { a -= b; } vector<int>g[N]; int pr[N]; void dfs(int v) { for (int to : g[v]) if (to != pr[v]) { pr[to] = v; dfs(to); } } ll binpow(ll a, ll b) { ll r = 1; while (b) { if (b & 1) r = r * a % L; a = a * a % L; b >>= 1; } return r; } ll ih[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> L; for (int i = 1 ; i < n ; ++ i) { int a, b; cin >> a >> b; g[a].emplace_back(b); g[b].emplace_back(a); } dfs(1); for (int i = 1 ; i <= n ; ++ i) { cin >> ih[i]; h[i] = 0; for (int j = 0 ; j <= 40 ; ++ j) { //q[i][j] = 1; q[i][j] = 0; } } int qq; cin >> qq; for (int i = 0 ; i < qq ; ++ i) { int t, x, d, w; cin >> t; if (t == 1) { cin >> x >> d >> w; w = 1; for (int i = d ; i >= 0 ; -- i) { mult(q[x][i], w); mult(h[x], w); if (x == 1) break; x = pr[x]; } } else { cin >> x; ll ret = ih[x]; ll ans = 0; for (int i = 0 ; i <= 40 ; ++ i) { mult(ans, q[x][i]); mult(ans, q[x][i+1]); if (x == 1) break; x = pr[x]; } if (ans > 0) { ans = 0; } else { ans = ret; } cout << ans << "\n"; //cout << ret*binpow(2, ans) % L << "\n"; } } }
#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...