# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569646 | 2022-05-27T15:15:12 Z | jamezzz | Sprinkler (JOI22_sprinkler) | C++17 | 818 ms | 92948 KB |
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define dbg(...) printf(__VA_ARGS__); #define getchar_unlocked getchar #else #define dbg(...) #endif #define sf scanf #define pf printf #define fi first #define se second #define pb push_back #define sz(x) (int)x.size() #define mnto(x,y) x=min(x,(__typeof__(x))y) #define mxto(x,y) x=max(x,(__typeof__(x))y) #define INF 1023456789 #define LINF 1023456789123456789 #define all(x) x.begin(), x.end() #define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin()); typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vll; mt19937 rng(time(0)); #define mod 1000000007 inline int rd(){ int x=0; char ch=getchar_unlocked(); while(!(ch&16))ch=getchar();//keep reading while current character is whitespace while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered x=(x<<3)+(x<<1)+(ch&15); ch=getchar_unlocked(); } return x; } #define maxn 200005 int n,l,q,h[maxn],par[maxn]; ll mult[maxn][45]; //mult[i][j]: at node i, this thing can travel j more vi AL[maxn]; void dfs(int u){ for(int v:AL[u]){ if(v==par[u])continue; par[v]=u; dfs(v); } } int main(){ sf("%d%d",&n,&l); for(int i=0;i<n-1;++i){ int a,b;sf("%d%d",&a,&b); AL[a].pb(b); AL[b].pb(a); } for(int i=1;i<=n;++i){ sf("%d",&h[i]); } dfs(1); for(int i=0;i<=n;++i){ for(int j=0;j<=41;++j){ mult[i][j]=1; } } sf("%d",&q); while(q--){ int t;sf("%d",&t); if(t==1){ int x,d,w;sf("%d%d%d",&x,&d,&w); int cur=x; for(int i=d;i>=0;--i){ mult[cur][i]*=w; mult[cur][i]%=l; if(par[cur]==0){ for(int j=i-1;j>=0;--j){ mult[cur][j]*=w; mult[cur][j]%=l; } break; } else cur=par[cur]; } /* for(int i=1;i<=4;++i){ pf("mult[%d]: ",i); for(int j=0;j<=4;++j){ pf("%lld ",mult[i][j]); } pf("\n"); } */ } else{ int x;sf("%d",&x); ll ans=h[x]; int cur=x,d=0; while(d!=40&&cur!=0){ ans*=mult[cur][d]; ans%=l; if(par[cur]!=0){ ans*=mult[cur][d+1]; ans%=l; } cur=par[cur]; ++d; } pf("%lld\n",ans); } } } /* 4 7 1 2 2 3 3 4 1 1 1 1 11 1 2 1 2 1 1 0 2 2 1 2 2 2 3 2 4 1 4 10 2 2 1 2 2 2 3 2 4 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 5 ms | 5012 KB | Output is correct |
4 | Incorrect | 5 ms | 5452 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 815 ms | 86956 KB | Output is correct |
3 | Correct | 496 ms | 83868 KB | Output is correct |
4 | Correct | 712 ms | 89368 KB | Output is correct |
5 | Correct | 649 ms | 85444 KB | Output is correct |
6 | Correct | 494 ms | 85384 KB | Output is correct |
7 | Correct | 400 ms | 85868 KB | Output is correct |
8 | Correct | 327 ms | 86040 KB | Output is correct |
9 | Correct | 818 ms | 92948 KB | Output is correct |
10 | Correct | 479 ms | 89272 KB | Output is correct |
11 | Correct | 743 ms | 87080 KB | Output is correct |
12 | Correct | 478 ms | 83948 KB | Output is correct |
13 | Correct | 340 ms | 84396 KB | Output is correct |
14 | Correct | 305 ms | 84532 KB | Output is correct |
15 | Correct | 315 ms | 84392 KB | Output is correct |
16 | Correct | 284 ms | 84352 KB | Output is correct |
17 | Correct | 320 ms | 84956 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 5024 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 815 ms | 86956 KB | Output is correct |
3 | Correct | 496 ms | 83868 KB | Output is correct |
4 | Correct | 712 ms | 89368 KB | Output is correct |
5 | Correct | 649 ms | 85444 KB | Output is correct |
6 | Correct | 494 ms | 85384 KB | Output is correct |
7 | Correct | 400 ms | 85868 KB | Output is correct |
8 | Correct | 327 ms | 86040 KB | Output is correct |
9 | Correct | 818 ms | 92948 KB | Output is correct |
10 | Correct | 479 ms | 89272 KB | Output is correct |
11 | Correct | 743 ms | 87080 KB | Output is correct |
12 | Correct | 478 ms | 83948 KB | Output is correct |
13 | Correct | 340 ms | 84396 KB | Output is correct |
14 | Correct | 305 ms | 84532 KB | Output is correct |
15 | Correct | 315 ms | 84392 KB | Output is correct |
16 | Correct | 284 ms | 84352 KB | Output is correct |
17 | Correct | 320 ms | 84956 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 5024 KB | Output is correct |
21 | Correct | 3 ms | 4948 KB | Output is correct |
22 | Correct | 3 ms | 4948 KB | Output is correct |
23 | Correct | 3 ms | 4948 KB | Output is correct |
24 | Correct | 729 ms | 87044 KB | Output is correct |
25 | Correct | 490 ms | 83840 KB | Output is correct |
26 | Correct | 630 ms | 91100 KB | Output is correct |
27 | Correct | 491 ms | 85372 KB | Output is correct |
28 | Correct | 405 ms | 85552 KB | Output is correct |
29 | Correct | 398 ms | 85588 KB | Output is correct |
30 | Correct | 301 ms | 86104 KB | Output is correct |
31 | Correct | 745 ms | 91116 KB | Output is correct |
32 | Correct | 469 ms | 89312 KB | Output is correct |
33 | Correct | 628 ms | 86992 KB | Output is correct |
34 | Correct | 451 ms | 83932 KB | Output is correct |
35 | Correct | 3 ms | 5020 KB | Output is correct |
36 | Correct | 3 ms | 4980 KB | Output is correct |
37 | Correct | 3 ms | 5016 KB | Output is correct |
38 | Correct | 3 ms | 4948 KB | Output is correct |
39 | Correct | 4 ms | 4948 KB | Output is correct |
40 | Correct | 3 ms | 4948 KB | Output is correct |
41 | Correct | 3 ms | 5024 KB | Output is correct |
42 | Correct | 3 ms | 4948 KB | Output is correct |
43 | Correct | 3 ms | 4948 KB | Output is correct |
44 | Correct | 3 ms | 4948 KB | Output is correct |
45 | Correct | 3 ms | 4948 KB | Output is correct |
46 | Correct | 3 ms | 4948 KB | Output is correct |
47 | Correct | 3 ms | 4948 KB | Output is correct |
48 | Correct | 3 ms | 5020 KB | Output is correct |
49 | Correct | 3 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4948 KB | Output is correct |
2 | Incorrect | 736 ms | 90304 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Incorrect | 755 ms | 91032 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 5 ms | 5012 KB | Output is correct |
4 | Incorrect | 5 ms | 5452 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |