Submission #1025158

#TimeUsernameProblemLanguageResultExecution timeMemory
1025158underwaterkillerwhaleSprinkler (JOI22_sprinkler)C++17
100 / 100
1518 ms174604 KiB
#include <bits/stdc++.h> #define se second #define fs first #define pb push_back #define ll long long #define ii pair<ll,ll> #define ld long double #define SZ(v) (int)v.size() #define ALL(v) v.begin(), v.end() #define bit(msk, i) ((msk >> i) & 1) #define iter(id, v) for(auto id : v) #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) using namespace std; mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count()); ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); } const int N = 2e5 + 7; ll Mod = 1e9 + 7; const int szBL = 916; const ll INF = 1e9; const int BASE = 137; int n, Q; ll a[N]; ll val[N][45], par[N][45]; vector<int> ke[N]; void dfs (int u, int p){ par[u][1] = p; par[u][0] = u; rep (i, 2, 40) par[u][i] = par[par[u][i - 1]][1]; iter (&v, ke[u]) { if (v != p) dfs (v, u); } } void update (int u, int d, ll w) { rep (i, 0, d) { if (par[u][i] == 0) { reb (j, d - i, 0) (val[0][j] *= w) %= Mod; return; } rep (j, d - i - 1, d - i) (val[par[u][i]][j] *= w) %= Mod; } } ll get (int x, int de) { if (x == 0 || de == 41) return val[x][de]; return val[x][de] * get (par[x][1], de + 1) % Mod; } void solution () { cin >> n >> Mod; rep (i, 1, n - 1) { int u, v; cin >> u >> v; ke[u].push_back(v); ke[v].push_back(u); } rep (i, 0, n) rep (j, 0, 41) val[i][j] = 1; rep (i, 1, n) cin >> a[i], val[i][0] = a[i]; dfs (1, 0); cin >> Q; rep (i, 1, Q) { int typ; cin >> typ; if (typ == 1) { ll x, d, w; cin >>x >> d >> w; update (x, d, w); } else { ll x; cin >> x; cout << get (x, 0) <<"\n"; } } } #define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); int main () { // file("c"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll num_Test = 1; // cin >> num_Test; while(num_Test--) solution(); } /* */
#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...