제출 #1200781

#제출 시각아이디문제언어결과실행 시간메모리
1200781mychecksedadSprinkler (JOI22_sprinkler)C++20
100 / 100
744 ms120096 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' #define ff first #define ss second #define pii pair<int,int> #define vi vector<int> const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; int n, par[N]; ll L, h[N][K]; vi g[N]; void dfs(int v, int p){ par[v] = p; for(int u: g[v]){ if(u != p){ dfs(u, v); } } } void solve(){ cin >> n >> L; for(int i = 1; i < n; ++i){ int a, b; cin >> a >> b; a += K; b += K; g[a].pb(b); g[b].pb(a); } for(int i = 1; i <= K; ++i){ g[i].pb(i+1); g[i+1].pb(i); } dfs(1, 1); for(int i = 1; i <= n + K; ++i){ for(int j = 0; j < K; ++j) h[i][j] = 1; } for(int i = 1; i <= n; ++i){ cin >> h[i + K][0]; } int q; cin >> q; for(int i = 1; i <= q; ++i){ int tp; cin >> tp; if(tp == 1){ int v, d; ll w; cin >> v >> d >> w; v += K; for(; d >= 0; d--){ h[v][d] *= w; h[v][d] %= L; v = par[v]; } }else{ int v; cin >> v; v += K; ll res = 1; for(int d = 0; d < K; ++d){ res *= h[v][d]; res %= L; if(d + 1 < K){ res *= h[v][d + 1]; res %= L; } v = par[v]; } cout << res << '\n'; } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\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...