Submission #671953

#TimeUsernameProblemLanguageResultExecution timeMemory
671953EvirirSprinkler (JOI22_sprinkler)C++17
100 / 100
1549 ms103692 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2") #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define cbug if(DEBUG) cout #define setp(x) cout<<fixed<<setprecision(x) #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; //template<typename T> //using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void SD(int t=0){ cout<<"PASSED "<<t<<endl; } ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; } template<typename T> void amax(T &a, T b){ a=max(a,b); } template<typename T> void amin(T &a, T b){ a=min(a,b); } const ll INF = ll(1e18); ll MOD; ll add(ll a, ll b, ll m = MOD) { a+=b; if(abs(a)>=m) a%=m; if(a<0) a+=m; return a; } ll mult(ll a, ll b, ll m = MOD) { if(abs(a)>=m) a%=m; if(abs(b)>=m) b%=m; a*=b; if(abs(a)>=m) a%=m; if(a<0) a+=m; return a; } const bool DEBUG = 0; const int MAXN = 200005; const int LG = 21; const int MAXD = 41; void dfs(int u, int p, const vector<vector<int>> &adj, vector<int> &prt) { prt[u] = p; for (int v : adj[u]) { if (v == p) continue; dfs(v, u, adj, prt); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; vector<ll> h; vector<vector<int>> adj; vector<vector<ll>> depthProd; vector<int> prt; cin >> n >> MOD; adj.resize(n); h.resize(n); prt.resize(n, -1); depthProd.resize(n, vector<ll>(MAXD + 1, 1)); forn(i,0,n-1) { int u,v; cin>>u>>v; u--; v--; adj[u].pb(v); adj[v].pb(u); } forn(i, 0, n) cin >> h[i]; dfs(0, -1, adj, prt); int Q; cin >> Q; while (Q--) { int t; cin>>t; if (t == 1) { int u, d; ll w; cin >> u >> d >> w; u--; for (int i = 0; i <= d; i++) { depthProd[u][d - i] = mult(depthProd[u][d - i], w); u = prt[u]; if (u == -1) break; } } else { int u; cin >> u; u--; ll prod = h[u]; for (int i = 0; i <= MAXD; i++) { if (i == MAXD || u == 0) { for (int j = i; j <= MAXD; j++) prod = mult(prod, depthProd[u][j]); } else { prod = mult(prod, depthProd[u][i]); if (i + 1 <= MAXD) { prod = mult(prod, depthProd[u][i + 1]); } } u = prt[u]; if (u == -1) break; } cout << prod << '\n'; } } 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...