# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
892568 | 2023-12-25T14:01:55 Z | ReLice | Sprinkler (JOI22_sprinkler) | C++14 | 606 ms | 105440 KB |
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define mpa make_pair #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define bc back() #define ar array #define vll vector<ll> using namespace std;/* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds;*/ template <class _T> bool chmin(_T &x, const _T &y){ if(x>y){ x=y; return true; } return false; } template <class _T> bool chmax(_T &x, const _T &y){ bool flag=false; if (x<y){ x=y;flag|=true; } return flag; } //#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=2e18+7; const ll mod=1e9+7; const ll N=2e5+7; const ld eps=1e-9; vector<vll> g(N); ll h[N]; ll i; ll n,k,p[N]; ll val[N][50]; void dfs(ll v,ll p,ll w,ll d,ll r){ h[v]*=w; h[v]%=k; if(d==r)return; for(auto i : g[v]){ if(i==p)continue; dfs(i,v,w,d+1,r); } } void dfs2(ll v){ for(auto i : g[v]){ if(i==p[v])continue; p[i]=v; dfs2(i); } } void solve(){ ll i,j,q; ll a,b,c; cin>>n>>k; for(i=0;i<=n;i++){ for(j=0;j<=45;j++)val[i][j]=1; } for(i=1;i<n;i++){ cin>>a>>b; g[a].pb(b); g[b].pb(a); } for(i=1;i<=n;i++)cin>>h[i]; dfs2(1); cin>>q; ll t; for(i=0;i<q;i++){ cin>>t; if(t==1){ cin>>a>>b>>c; while(p[a] && b){ val[a][b]*=c; val[a][b-1]*=c; val[a][b]%=k; val[a][b-1]%=k; a=p[a]; b--; } while(b){ val[a][b]*=c; val[a][b]%=k; b--; } val[a][0]*=c; val[a][0]%=k; }else{ cin>>a; ll ans=h[a]*val[a][0]%k; for(j=1;j<=40;j++){ a=p[a]; if(a==0)break; ans*=val[a][j]; ans%=k; } cout<<ans<<endl; } } } signed main(){ start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* 1 7 1 2 2 3 3 4 4 5 3 6 6 7 2 4 1 5 7 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7000 KB | Output is correct |
2 | Correct | 2 ms | 7000 KB | Output is correct |
3 | Correct | 1 ms | 7004 KB | Output is correct |
4 | Correct | 3 ms | 9304 KB | Output is correct |
5 | Correct | 3 ms | 9308 KB | Output is correct |
6 | Correct | 2 ms | 9308 KB | Output is correct |
7 | Correct | 3 ms | 9308 KB | Output is correct |
8 | Correct | 2 ms | 9560 KB | Output is correct |
9 | Correct | 2 ms | 7004 KB | Output is correct |
10 | Correct | 2 ms | 7004 KB | Output is correct |
11 | Correct | 2 ms | 7004 KB | Output is correct |
12 | Correct | 2 ms | 7004 KB | Output is correct |
13 | Correct | 2 ms | 7004 KB | Output is correct |
14 | Correct | 2 ms | 7004 KB | Output is correct |
15 | Correct | 2 ms | 7004 KB | Output is correct |
16 | Correct | 2 ms | 7004 KB | Output is correct |
17 | Correct | 2 ms | 7004 KB | Output is correct |
18 | Correct | 2 ms | 7228 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
20 | Correct | 2 ms | 7004 KB | Output is correct |
21 | Correct | 2 ms | 7224 KB | Output is correct |
22 | Correct | 2 ms | 7004 KB | Output is correct |
23 | Correct | 2 ms | 7004 KB | Output is correct |
24 | Correct | 2 ms | 7004 KB | Output is correct |
25 | Correct | 2 ms | 7004 KB | Output is correct |
26 | Correct | 2 ms | 7004 KB | Output is correct |
27 | Correct | 2 ms | 7256 KB | Output is correct |
28 | Correct | 2 ms | 7004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7004 KB | Output is correct |
2 | Correct | 410 ms | 97616 KB | Output is correct |
3 | Correct | 251 ms | 94184 KB | Output is correct |
4 | Correct | 374 ms | 100920 KB | Output is correct |
5 | Correct | 294 ms | 95628 KB | Output is correct |
6 | Correct | 223 ms | 95704 KB | Output is correct |
7 | Correct | 225 ms | 96084 KB | Output is correct |
8 | Correct | 203 ms | 96192 KB | Output is correct |
9 | Correct | 444 ms | 105440 KB | Output is correct |
10 | Correct | 267 ms | 101456 KB | Output is correct |
11 | Correct | 368 ms | 97344 KB | Output is correct |
12 | Correct | 238 ms | 94032 KB | Output is correct |
13 | Correct | 183 ms | 94608 KB | Output is correct |
14 | Correct | 175 ms | 94472 KB | Output is correct |
15 | Correct | 163 ms | 94388 KB | Output is correct |
16 | Correct | 177 ms | 94452 KB | Output is correct |
17 | Correct | 174 ms | 95060 KB | Output is correct |
18 | Correct | 2 ms | 7004 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
20 | Correct | 2 ms | 7004 KB | Output is correct |
21 | Correct | 2 ms | 7000 KB | Output is correct |
22 | Correct | 3 ms | 7004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7004 KB | Output is correct |
2 | Correct | 410 ms | 97616 KB | Output is correct |
3 | Correct | 251 ms | 94184 KB | Output is correct |
4 | Correct | 374 ms | 100920 KB | Output is correct |
5 | Correct | 294 ms | 95628 KB | Output is correct |
6 | Correct | 223 ms | 95704 KB | Output is correct |
7 | Correct | 225 ms | 96084 KB | Output is correct |
8 | Correct | 203 ms | 96192 KB | Output is correct |
9 | Correct | 444 ms | 105440 KB | Output is correct |
10 | Correct | 267 ms | 101456 KB | Output is correct |
11 | Correct | 368 ms | 97344 KB | Output is correct |
12 | Correct | 238 ms | 94032 KB | Output is correct |
13 | Correct | 183 ms | 94608 KB | Output is correct |
14 | Correct | 175 ms | 94472 KB | Output is correct |
15 | Correct | 163 ms | 94388 KB | Output is correct |
16 | Correct | 177 ms | 94452 KB | Output is correct |
17 | Correct | 174 ms | 95060 KB | Output is correct |
18 | Correct | 2 ms | 7004 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
20 | Correct | 2 ms | 7004 KB | Output is correct |
21 | Correct | 2 ms | 7000 KB | Output is correct |
22 | Correct | 3 ms | 7004 KB | Output is correct |
23 | Correct | 1 ms | 7004 KB | Output is correct |
24 | Correct | 416 ms | 97368 KB | Output is correct |
25 | Correct | 278 ms | 94036 KB | Output is correct |
26 | Correct | 383 ms | 103484 KB | Output is correct |
27 | Correct | 317 ms | 95828 KB | Output is correct |
28 | Correct | 275 ms | 95944 KB | Output is correct |
29 | Correct | 280 ms | 95828 KB | Output is correct |
30 | Correct | 209 ms | 96252 KB | Output is correct |
31 | Correct | 517 ms | 102580 KB | Output is correct |
32 | Correct | 305 ms | 101616 KB | Output is correct |
33 | Correct | 366 ms | 97312 KB | Output is correct |
34 | Correct | 273 ms | 94292 KB | Output is correct |
35 | Correct | 2 ms | 7004 KB | Output is correct |
36 | Correct | 2 ms | 7004 KB | Output is correct |
37 | Correct | 2 ms | 7000 KB | Output is correct |
38 | Correct | 2 ms | 7004 KB | Output is correct |
39 | Correct | 2 ms | 7004 KB | Output is correct |
40 | Correct | 2 ms | 7004 KB | Output is correct |
41 | Correct | 2 ms | 7004 KB | Output is correct |
42 | Correct | 2 ms | 7004 KB | Output is correct |
43 | Correct | 2 ms | 7016 KB | Output is correct |
44 | Correct | 2 ms | 7004 KB | Output is correct |
45 | Correct | 2 ms | 7256 KB | Output is correct |
46 | Correct | 2 ms | 7004 KB | Output is correct |
47 | Correct | 2 ms | 7004 KB | Output is correct |
48 | Correct | 2 ms | 7004 KB | Output is correct |
49 | Correct | 2 ms | 7004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7004 KB | Output is correct |
2 | Correct | 479 ms | 102652 KB | Output is correct |
3 | Correct | 603 ms | 99780 KB | Output is correct |
4 | Correct | 410 ms | 100436 KB | Output is correct |
5 | Correct | 366 ms | 94292 KB | Output is correct |
6 | Correct | 260 ms | 94292 KB | Output is correct |
7 | Correct | 243 ms | 94800 KB | Output is correct |
8 | Correct | 195 ms | 94536 KB | Output is correct |
9 | Correct | 469 ms | 99956 KB | Output is correct |
10 | Correct | 583 ms | 101064 KB | Output is correct |
11 | Correct | 349 ms | 94608 KB | Output is correct |
12 | Correct | 399 ms | 94220 KB | Output is correct |
13 | Correct | 316 ms | 94844 KB | Output is correct |
14 | Correct | 308 ms | 95632 KB | Output is correct |
15 | Correct | 2 ms | 7000 KB | Output is correct |
16 | Correct | 2 ms | 7004 KB | Output is correct |
17 | Correct | 1 ms | 7004 KB | Output is correct |
18 | Correct | 1 ms | 7004 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6964 KB | Output is correct |
2 | Correct | 452 ms | 102248 KB | Output is correct |
3 | Correct | 549 ms | 97876 KB | Output is correct |
4 | Correct | 491 ms | 100032 KB | Output is correct |
5 | Correct | 357 ms | 95860 KB | Output is correct |
6 | Correct | 279 ms | 95960 KB | Output is correct |
7 | Correct | 249 ms | 95976 KB | Output is correct |
8 | Correct | 200 ms | 96204 KB | Output is correct |
9 | Correct | 476 ms | 104568 KB | Output is correct |
10 | Correct | 573 ms | 101684 KB | Output is correct |
11 | Correct | 401 ms | 97676 KB | Output is correct |
12 | Correct | 380 ms | 94200 KB | Output is correct |
13 | Correct | 316 ms | 95316 KB | Output is correct |
14 | Correct | 309 ms | 95560 KB | Output is correct |
15 | Correct | 2 ms | 7004 KB | Output is correct |
16 | Correct | 1 ms | 7004 KB | Output is correct |
17 | Correct | 2 ms | 7004 KB | Output is correct |
18 | Correct | 2 ms | 7004 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7000 KB | Output is correct |
2 | Correct | 2 ms | 7000 KB | Output is correct |
3 | Correct | 1 ms | 7004 KB | Output is correct |
4 | Correct | 3 ms | 9304 KB | Output is correct |
5 | Correct | 3 ms | 9308 KB | Output is correct |
6 | Correct | 2 ms | 9308 KB | Output is correct |
7 | Correct | 3 ms | 9308 KB | Output is correct |
8 | Correct | 2 ms | 9560 KB | Output is correct |
9 | Correct | 2 ms | 7004 KB | Output is correct |
10 | Correct | 2 ms | 7004 KB | Output is correct |
11 | Correct | 2 ms | 7004 KB | Output is correct |
12 | Correct | 2 ms | 7004 KB | Output is correct |
13 | Correct | 2 ms | 7004 KB | Output is correct |
14 | Correct | 2 ms | 7004 KB | Output is correct |
15 | Correct | 2 ms | 7004 KB | Output is correct |
16 | Correct | 2 ms | 7004 KB | Output is correct |
17 | Correct | 2 ms | 7004 KB | Output is correct |
18 | Correct | 2 ms | 7228 KB | Output is correct |
19 | Correct | 2 ms | 7004 KB | Output is correct |
20 | Correct | 2 ms | 7004 KB | Output is correct |
21 | Correct | 2 ms | 7224 KB | Output is correct |
22 | Correct | 2 ms | 7004 KB | Output is correct |
23 | Correct | 2 ms | 7004 KB | Output is correct |
24 | Correct | 2 ms | 7004 KB | Output is correct |
25 | Correct | 2 ms | 7004 KB | Output is correct |
26 | Correct | 2 ms | 7004 KB | Output is correct |
27 | Correct | 2 ms | 7256 KB | Output is correct |
28 | Correct | 2 ms | 7004 KB | Output is correct |
29 | Correct | 2 ms | 7004 KB | Output is correct |
30 | Correct | 410 ms | 97616 KB | Output is correct |
31 | Correct | 251 ms | 94184 KB | Output is correct |
32 | Correct | 374 ms | 100920 KB | Output is correct |
33 | Correct | 294 ms | 95628 KB | Output is correct |
34 | Correct | 223 ms | 95704 KB | Output is correct |
35 | Correct | 225 ms | 96084 KB | Output is correct |
36 | Correct | 203 ms | 96192 KB | Output is correct |
37 | Correct | 444 ms | 105440 KB | Output is correct |
38 | Correct | 267 ms | 101456 KB | Output is correct |
39 | Correct | 368 ms | 97344 KB | Output is correct |
40 | Correct | 238 ms | 94032 KB | Output is correct |
41 | Correct | 183 ms | 94608 KB | Output is correct |
42 | Correct | 175 ms | 94472 KB | Output is correct |
43 | Correct | 163 ms | 94388 KB | Output is correct |
44 | Correct | 177 ms | 94452 KB | Output is correct |
45 | Correct | 174 ms | 95060 KB | Output is correct |
46 | Correct | 2 ms | 7004 KB | Output is correct |
47 | Correct | 2 ms | 7004 KB | Output is correct |
48 | Correct | 2 ms | 7004 KB | Output is correct |
49 | Correct | 2 ms | 7000 KB | Output is correct |
50 | Correct | 3 ms | 7004 KB | Output is correct |
51 | Correct | 1 ms | 7004 KB | Output is correct |
52 | Correct | 416 ms | 97368 KB | Output is correct |
53 | Correct | 278 ms | 94036 KB | Output is correct |
54 | Correct | 383 ms | 103484 KB | Output is correct |
55 | Correct | 317 ms | 95828 KB | Output is correct |
56 | Correct | 275 ms | 95944 KB | Output is correct |
57 | Correct | 280 ms | 95828 KB | Output is correct |
58 | Correct | 209 ms | 96252 KB | Output is correct |
59 | Correct | 517 ms | 102580 KB | Output is correct |
60 | Correct | 305 ms | 101616 KB | Output is correct |
61 | Correct | 366 ms | 97312 KB | Output is correct |
62 | Correct | 273 ms | 94292 KB | Output is correct |
63 | Correct | 2 ms | 7004 KB | Output is correct |
64 | Correct | 2 ms | 7004 KB | Output is correct |
65 | Correct | 2 ms | 7000 KB | Output is correct |
66 | Correct | 2 ms | 7004 KB | Output is correct |
67 | Correct | 2 ms | 7004 KB | Output is correct |
68 | Correct | 2 ms | 7004 KB | Output is correct |
69 | Correct | 2 ms | 7004 KB | Output is correct |
70 | Correct | 2 ms | 7004 KB | Output is correct |
71 | Correct | 2 ms | 7016 KB | Output is correct |
72 | Correct | 2 ms | 7004 KB | Output is correct |
73 | Correct | 2 ms | 7256 KB | Output is correct |
74 | Correct | 2 ms | 7004 KB | Output is correct |
75 | Correct | 2 ms | 7004 KB | Output is correct |
76 | Correct | 2 ms | 7004 KB | Output is correct |
77 | Correct | 2 ms | 7004 KB | Output is correct |
78 | Correct | 2 ms | 7004 KB | Output is correct |
79 | Correct | 479 ms | 102652 KB | Output is correct |
80 | Correct | 603 ms | 99780 KB | Output is correct |
81 | Correct | 410 ms | 100436 KB | Output is correct |
82 | Correct | 366 ms | 94292 KB | Output is correct |
83 | Correct | 260 ms | 94292 KB | Output is correct |
84 | Correct | 243 ms | 94800 KB | Output is correct |
85 | Correct | 195 ms | 94536 KB | Output is correct |
86 | Correct | 469 ms | 99956 KB | Output is correct |
87 | Correct | 583 ms | 101064 KB | Output is correct |
88 | Correct | 349 ms | 94608 KB | Output is correct |
89 | Correct | 399 ms | 94220 KB | Output is correct |
90 | Correct | 316 ms | 94844 KB | Output is correct |
91 | Correct | 308 ms | 95632 KB | Output is correct |
92 | Correct | 2 ms | 7000 KB | Output is correct |
93 | Correct | 2 ms | 7004 KB | Output is correct |
94 | Correct | 1 ms | 7004 KB | Output is correct |
95 | Correct | 1 ms | 7004 KB | Output is correct |
96 | Correct | 2 ms | 7004 KB | Output is correct |
97 | Correct | 2 ms | 6964 KB | Output is correct |
98 | Correct | 452 ms | 102248 KB | Output is correct |
99 | Correct | 549 ms | 97876 KB | Output is correct |
100 | Correct | 491 ms | 100032 KB | Output is correct |
101 | Correct | 357 ms | 95860 KB | Output is correct |
102 | Correct | 279 ms | 95960 KB | Output is correct |
103 | Correct | 249 ms | 95976 KB | Output is correct |
104 | Correct | 200 ms | 96204 KB | Output is correct |
105 | Correct | 476 ms | 104568 KB | Output is correct |
106 | Correct | 573 ms | 101684 KB | Output is correct |
107 | Correct | 401 ms | 97676 KB | Output is correct |
108 | Correct | 380 ms | 94200 KB | Output is correct |
109 | Correct | 316 ms | 95316 KB | Output is correct |
110 | Correct | 309 ms | 95560 KB | Output is correct |
111 | Correct | 2 ms | 7004 KB | Output is correct |
112 | Correct | 1 ms | 7004 KB | Output is correct |
113 | Correct | 2 ms | 7004 KB | Output is correct |
114 | Correct | 2 ms | 7004 KB | Output is correct |
115 | Correct | 2 ms | 7004 KB | Output is correct |
116 | Correct | 391 ms | 95548 KB | Output is correct |
117 | Correct | 473 ms | 93924 KB | Output is correct |
118 | Correct | 435 ms | 103440 KB | Output is correct |
119 | Correct | 410 ms | 95888 KB | Output is correct |
120 | Correct | 280 ms | 95576 KB | Output is correct |
121 | Correct | 285 ms | 96108 KB | Output is correct |
122 | Correct | 216 ms | 96288 KB | Output is correct |
123 | Correct | 472 ms | 103508 KB | Output is correct |
124 | Correct | 606 ms | 98712 KB | Output is correct |
125 | Correct | 391 ms | 96812 KB | Output is correct |
126 | Correct | 500 ms | 94084 KB | Output is correct |
127 | Correct | 471 ms | 94036 KB | Output is correct |
128 | Correct | 427 ms | 95408 KB | Output is correct |
129 | Correct | 430 ms | 95572 KB | Output is correct |