Submission #876630

#TimeUsernameProblemLanguageResultExecution timeMemory
876630n3rm1nSprinkler (JOI22_sprinkler)C++17
100 / 100
651 ms187984 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const long long MAXN = 4e5; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n, mod; vector < long long > g[MAXN]; long long h[MAXN]; void read() { cin >> n >> mod; long long xx, yy; for (long long i = 1; i < n; ++ i) { cin >> xx >> yy; g[xx].push_back(yy); g[yy].push_back(xx); } for (long long i = 1; i <= n; ++ i) cin >> h[i]; } ///long long tin[MAXN], tout[MAXN]; long long used[MAXN]; long long p[MAXN]; ///vector < long long > on_lvls[MAXN]; long long timerr = 0; void dfs(long long beg, long long parent, long long depth) { /// tin[beg] = timerr; p[beg] = parent; used[beg] = 1; ///on_lvls[depth].push_back(beg); long long nb; /// children = 0; for (long long i = 0; i < g[beg].size(); ++ i) { nb = g[beg][i]; if(!used[nb]) { /// children ++; dfs(nb, beg, depth + 1); } } /**if(children) { timerr ++; tout[beg] = timerr; }*/ } long long x, d, w; long long upd[MAXN][88]; void print_upd() { for (long long i = 1; i <= n; ++ i) { cout << "upd for vertex " << i << " " << endl; cout << "depth : "; for (long long j = 0; j <= 3; ++ j) cout << upd[i][j] << ", "; cout << endl; } } void update_arrays() { /// cout << "***" << endl; long long vertex = x, depth = d; while(vertex != 1 && depth >= 0) { upd[vertex][depth] *= w; upd[vertex][depth] %= mod; if(depth) { upd[vertex][depth-1] *= w; upd[vertex][depth-1] %= mod; } ///cout << vertex << " " << depth << " " << upd[vertex][depth] << endl; ///cout << vertex << " " << depth-1 << " " << upd[vertex][depth-1] << endl; vertex = p[vertex]; depth --; } if(vertex == 1) { for (long long i = 0; i <= depth; ++ i) { upd[1][i] *= w; upd[1][i] %= mod; } } } void solve_query() { long long anc = x, lvl_diff = 0; long long ans = h[x]; //cout << "solving for v = " << anc << endl; while(anc && lvl_diff <= 40) { //cout << "anc = " << anc << " " << "mult is " << upd[anc][lvl_diff] << endl; ans = ans * upd[anc][lvl_diff]; ans %= mod; anc = p[anc]; lvl_diff ++; } cout << ans << endl; } void queries() { long long q; cin >> q; long long type; while(q --) { cin >> type; if(type == 1) { cin >> x >> d >> w; update_arrays(); ///prlong long_upd(); } else { cin >> x; solve_query(); } } } int main() { speed(); read(); for (long long i = 1; i <= n; ++ i) for (long long j = 0; j <= 80; ++ j) upd[i][j] = 1; dfs(1, 0, 1); queries(); return 0; }

Compilation message (stderr)

sprinkler.cpp: In function 'void dfs(long long int, long long int, long long int)':
sprinkler.cpp:46:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (long long i = 0; i < g[beg].size(); ++ i)
      |                           ~~^~~~~~~~~~~~~~~
#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...