# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
893044 | 2023-12-26T12:01:17 Z | vjudge1 | Sprinkler (JOI22_sprinkler) | C++17 | 898 ms | 110164 KB |
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define int long long #define rnd(l, r) uniform_int_distribution<int>(l, r)(rng) using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;} int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 2e5 + 10, inf = 1e9; vector <int> g[N]; int cost[N]; int h[N][50]; int par[N]; void dfs(int v, int p){ par[v] = p; for(auto to : g[v]){ if(to == p)continue; dfs(to, v); } } main(){ iostream::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, l; cin >> n >> l; for(int i = 0; i < n - 1; i ++){ int a, b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } for(int i = 1; i <= n; i++){ cin >> cost[i]; for(int j = 0; j <= 45; j++){ h[i][j] = 1; } } int q; cin >> q; dfs(1, 1); while(q--){ int tp; cin >> tp; if(tp == 1){ int x, d, w; cin >> x >> d >> w; while(d > 0 && par[x] != x){ h[x][d] =( h[x][d] * w) % l; h[x][d - 1] = (h[x][d - 1] * w) % l; x = par[x]; d--; } while(d > 0){ h[x][d] = (h[x][d] * w) % l; d--; } h[x][0] = (h[x][0] * w) % l; }else{ int x; cin >> x; int res = cost[x]; for(int i = 0; i <= 40; i++){ res *= h[x][i]; res %= l; if(x == par[x])break; x = par[x]; } cout << res % l<< endl; } } } /* * Before implementing the problem: Do I understand the problem correctly? Which places are tricky? What do I need to remember to implement them correctly? Which place is the heaviest by implementation? Can I do it simpler? Which place is the slowest? Where do I need to be careful about constant factors and where I can choose slower but simpler implementation? ---------------------------------- If not AC: Did you remember to do everything to handle the tricky places you thought about before? Is the solution correct? Do I understand the problem correctly? ---------------------------------- If you have a test on which the solution gives wrong answer: Is the solution doing what it was supposed to do? Is the problem in the code or in the idea? */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10332 KB | Output is correct |
2 | Correct | 2 ms | 10332 KB | Output is correct |
3 | Correct | 2 ms | 10344 KB | Output is correct |
4 | Correct | 3 ms | 10332 KB | Output is correct |
5 | Correct | 3 ms | 10328 KB | Output is correct |
6 | Correct | 3 ms | 10332 KB | Output is correct |
7 | Correct | 3 ms | 10548 KB | Output is correct |
8 | Correct | 3 ms | 10332 KB | Output is correct |
9 | Correct | 3 ms | 10332 KB | Output is correct |
10 | Correct | 3 ms | 10332 KB | Output is correct |
11 | Correct | 3 ms | 10428 KB | Output is correct |
12 | Correct | 4 ms | 10328 KB | Output is correct |
13 | Correct | 3 ms | 10332 KB | Output is correct |
14 | Correct | 3 ms | 10476 KB | Output is correct |
15 | Correct | 3 ms | 10328 KB | Output is correct |
16 | Correct | 3 ms | 10328 KB | Output is correct |
17 | Correct | 3 ms | 10332 KB | Output is correct |
18 | Correct | 3 ms | 10332 KB | Output is correct |
19 | Correct | 3 ms | 10332 KB | Output is correct |
20 | Correct | 3 ms | 10332 KB | Output is correct |
21 | Correct | 3 ms | 10332 KB | Output is correct |
22 | Correct | 3 ms | 10480 KB | Output is correct |
23 | Correct | 3 ms | 10332 KB | Output is correct |
24 | Correct | 3 ms | 10332 KB | Output is correct |
25 | Correct | 3 ms | 10332 KB | Output is correct |
26 | Correct | 3 ms | 10480 KB | Output is correct |
27 | Correct | 3 ms | 10464 KB | Output is correct |
28 | Correct | 3 ms | 10584 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10344 KB | Output is correct |
2 | Correct | 831 ms | 105564 KB | Output is correct |
3 | Correct | 297 ms | 105976 KB | Output is correct |
4 | Correct | 599 ms | 108256 KB | Output is correct |
5 | Correct | 556 ms | 105836 KB | Output is correct |
6 | Correct | 461 ms | 105496 KB | Output is correct |
7 | Correct | 459 ms | 106064 KB | Output is correct |
8 | Correct | 418 ms | 106368 KB | Output is correct |
9 | Correct | 839 ms | 109636 KB | Output is correct |
10 | Correct | 329 ms | 109868 KB | Output is correct |
11 | Correct | 763 ms | 105648 KB | Output is correct |
12 | Correct | 339 ms | 106036 KB | Output is correct |
13 | Correct | 219 ms | 106100 KB | Output is correct |
14 | Correct | 228 ms | 106928 KB | Output is correct |
15 | Correct | 220 ms | 105804 KB | Output is correct |
16 | Correct | 223 ms | 106324 KB | Output is correct |
17 | Correct | 235 ms | 106940 KB | Output is correct |
18 | Correct | 3 ms | 10332 KB | Output is correct |
19 | Correct | 3 ms | 10332 KB | Output is correct |
20 | Correct | 3 ms | 10328 KB | Output is correct |
21 | Correct | 3 ms | 10332 KB | Output is correct |
22 | Correct | 3 ms | 10476 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10344 KB | Output is correct |
2 | Correct | 831 ms | 105564 KB | Output is correct |
3 | Correct | 297 ms | 105976 KB | Output is correct |
4 | Correct | 599 ms | 108256 KB | Output is correct |
5 | Correct | 556 ms | 105836 KB | Output is correct |
6 | Correct | 461 ms | 105496 KB | Output is correct |
7 | Correct | 459 ms | 106064 KB | Output is correct |
8 | Correct | 418 ms | 106368 KB | Output is correct |
9 | Correct | 839 ms | 109636 KB | Output is correct |
10 | Correct | 329 ms | 109868 KB | Output is correct |
11 | Correct | 763 ms | 105648 KB | Output is correct |
12 | Correct | 339 ms | 106036 KB | Output is correct |
13 | Correct | 219 ms | 106100 KB | Output is correct |
14 | Correct | 228 ms | 106928 KB | Output is correct |
15 | Correct | 220 ms | 105804 KB | Output is correct |
16 | Correct | 223 ms | 106324 KB | Output is correct |
17 | Correct | 235 ms | 106940 KB | Output is correct |
18 | Correct | 3 ms | 10332 KB | Output is correct |
19 | Correct | 3 ms | 10332 KB | Output is correct |
20 | Correct | 3 ms | 10328 KB | Output is correct |
21 | Correct | 3 ms | 10332 KB | Output is correct |
22 | Correct | 3 ms | 10476 KB | Output is correct |
23 | Correct | 2 ms | 10332 KB | Output is correct |
24 | Correct | 791 ms | 105800 KB | Output is correct |
25 | Correct | 312 ms | 106084 KB | Output is correct |
26 | Correct | 604 ms | 109904 KB | Output is correct |
27 | Correct | 565 ms | 105616 KB | Output is correct |
28 | Correct | 470 ms | 106012 KB | Output is correct |
29 | Correct | 450 ms | 105696 KB | Output is correct |
30 | Correct | 412 ms | 106428 KB | Output is correct |
31 | Correct | 837 ms | 108168 KB | Output is correct |
32 | Correct | 343 ms | 110164 KB | Output is correct |
33 | Correct | 779 ms | 105520 KB | Output is correct |
34 | Correct | 313 ms | 106068 KB | Output is correct |
35 | Correct | 3 ms | 10332 KB | Output is correct |
36 | Correct | 3 ms | 10332 KB | Output is correct |
37 | Correct | 3 ms | 10332 KB | Output is correct |
38 | Correct | 3 ms | 10332 KB | Output is correct |
39 | Correct | 3 ms | 10332 KB | Output is correct |
40 | Correct | 3 ms | 10332 KB | Output is correct |
41 | Correct | 3 ms | 10252 KB | Output is correct |
42 | Correct | 3 ms | 10332 KB | Output is correct |
43 | Correct | 3 ms | 10332 KB | Output is correct |
44 | Correct | 3 ms | 10328 KB | Output is correct |
45 | Correct | 3 ms | 10332 KB | Output is correct |
46 | Correct | 3 ms | 10332 KB | Output is correct |
47 | Correct | 3 ms | 10332 KB | Output is correct |
48 | Correct | 3 ms | 10332 KB | Output is correct |
49 | Correct | 3 ms | 10328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10328 KB | Output is correct |
2 | Correct | 868 ms | 106920 KB | Output is correct |
3 | Correct | 635 ms | 105976 KB | Output is correct |
4 | Correct | 659 ms | 105952 KB | Output is correct |
5 | Correct | 572 ms | 102736 KB | Output is correct |
6 | Correct | 477 ms | 102992 KB | Output is correct |
7 | Correct | 464 ms | 103528 KB | Output is correct |
8 | Correct | 406 ms | 103556 KB | Output is correct |
9 | Correct | 870 ms | 105372 KB | Output is correct |
10 | Correct | 631 ms | 106836 KB | Output is correct |
11 | Correct | 792 ms | 102536 KB | Output is correct |
12 | Correct | 476 ms | 103336 KB | Output is correct |
13 | Correct | 342 ms | 104276 KB | Output is correct |
14 | Correct | 347 ms | 105112 KB | Output is correct |
15 | Correct | 3 ms | 10332 KB | Output is correct |
16 | Correct | 3 ms | 10332 KB | Output is correct |
17 | Correct | 3 ms | 10472 KB | Output is correct |
18 | Correct | 3 ms | 10332 KB | Output is correct |
19 | Correct | 3 ms | 10328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10332 KB | Output is correct |
2 | Correct | 898 ms | 104232 KB | Output is correct |
3 | Correct | 623 ms | 105288 KB | Output is correct |
4 | Correct | 665 ms | 106592 KB | Output is correct |
5 | Correct | 564 ms | 104528 KB | Output is correct |
6 | Correct | 488 ms | 104584 KB | Output is correct |
7 | Correct | 476 ms | 104276 KB | Output is correct |
8 | Correct | 421 ms | 104608 KB | Output is correct |
9 | Correct | 869 ms | 109316 KB | Output is correct |
10 | Correct | 626 ms | 107600 KB | Output is correct |
11 | Correct | 792 ms | 105212 KB | Output is correct |
12 | Correct | 443 ms | 103504 KB | Output is correct |
13 | Correct | 349 ms | 104388 KB | Output is correct |
14 | Correct | 342 ms | 105300 KB | Output is correct |
15 | Correct | 3 ms | 10332 KB | Output is correct |
16 | Correct | 3 ms | 10332 KB | Output is correct |
17 | Correct | 3 ms | 10332 KB | Output is correct |
18 | Correct | 3 ms | 10480 KB | Output is correct |
19 | Correct | 3 ms | 10328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10332 KB | Output is correct |
2 | Correct | 2 ms | 10332 KB | Output is correct |
3 | Correct | 2 ms | 10344 KB | Output is correct |
4 | Correct | 3 ms | 10332 KB | Output is correct |
5 | Correct | 3 ms | 10328 KB | Output is correct |
6 | Correct | 3 ms | 10332 KB | Output is correct |
7 | Correct | 3 ms | 10548 KB | Output is correct |
8 | Correct | 3 ms | 10332 KB | Output is correct |
9 | Correct | 3 ms | 10332 KB | Output is correct |
10 | Correct | 3 ms | 10332 KB | Output is correct |
11 | Correct | 3 ms | 10428 KB | Output is correct |
12 | Correct | 4 ms | 10328 KB | Output is correct |
13 | Correct | 3 ms | 10332 KB | Output is correct |
14 | Correct | 3 ms | 10476 KB | Output is correct |
15 | Correct | 3 ms | 10328 KB | Output is correct |
16 | Correct | 3 ms | 10328 KB | Output is correct |
17 | Correct | 3 ms | 10332 KB | Output is correct |
18 | Correct | 3 ms | 10332 KB | Output is correct |
19 | Correct | 3 ms | 10332 KB | Output is correct |
20 | Correct | 3 ms | 10332 KB | Output is correct |
21 | Correct | 3 ms | 10332 KB | Output is correct |
22 | Correct | 3 ms | 10480 KB | Output is correct |
23 | Correct | 3 ms | 10332 KB | Output is correct |
24 | Correct | 3 ms | 10332 KB | Output is correct |
25 | Correct | 3 ms | 10332 KB | Output is correct |
26 | Correct | 3 ms | 10480 KB | Output is correct |
27 | Correct | 3 ms | 10464 KB | Output is correct |
28 | Correct | 3 ms | 10584 KB | Output is correct |
29 | Correct | 2 ms | 10344 KB | Output is correct |
30 | Correct | 831 ms | 105564 KB | Output is correct |
31 | Correct | 297 ms | 105976 KB | Output is correct |
32 | Correct | 599 ms | 108256 KB | Output is correct |
33 | Correct | 556 ms | 105836 KB | Output is correct |
34 | Correct | 461 ms | 105496 KB | Output is correct |
35 | Correct | 459 ms | 106064 KB | Output is correct |
36 | Correct | 418 ms | 106368 KB | Output is correct |
37 | Correct | 839 ms | 109636 KB | Output is correct |
38 | Correct | 329 ms | 109868 KB | Output is correct |
39 | Correct | 763 ms | 105648 KB | Output is correct |
40 | Correct | 339 ms | 106036 KB | Output is correct |
41 | Correct | 219 ms | 106100 KB | Output is correct |
42 | Correct | 228 ms | 106928 KB | Output is correct |
43 | Correct | 220 ms | 105804 KB | Output is correct |
44 | Correct | 223 ms | 106324 KB | Output is correct |
45 | Correct | 235 ms | 106940 KB | Output is correct |
46 | Correct | 3 ms | 10332 KB | Output is correct |
47 | Correct | 3 ms | 10332 KB | Output is correct |
48 | Correct | 3 ms | 10328 KB | Output is correct |
49 | Correct | 3 ms | 10332 KB | Output is correct |
50 | Correct | 3 ms | 10476 KB | Output is correct |
51 | Correct | 2 ms | 10332 KB | Output is correct |
52 | Correct | 791 ms | 105800 KB | Output is correct |
53 | Correct | 312 ms | 106084 KB | Output is correct |
54 | Correct | 604 ms | 109904 KB | Output is correct |
55 | Correct | 565 ms | 105616 KB | Output is correct |
56 | Correct | 470 ms | 106012 KB | Output is correct |
57 | Correct | 450 ms | 105696 KB | Output is correct |
58 | Correct | 412 ms | 106428 KB | Output is correct |
59 | Correct | 837 ms | 108168 KB | Output is correct |
60 | Correct | 343 ms | 110164 KB | Output is correct |
61 | Correct | 779 ms | 105520 KB | Output is correct |
62 | Correct | 313 ms | 106068 KB | Output is correct |
63 | Correct | 3 ms | 10332 KB | Output is correct |
64 | Correct | 3 ms | 10332 KB | Output is correct |
65 | Correct | 3 ms | 10332 KB | Output is correct |
66 | Correct | 3 ms | 10332 KB | Output is correct |
67 | Correct | 3 ms | 10332 KB | Output is correct |
68 | Correct | 3 ms | 10332 KB | Output is correct |
69 | Correct | 3 ms | 10252 KB | Output is correct |
70 | Correct | 3 ms | 10332 KB | Output is correct |
71 | Correct | 3 ms | 10332 KB | Output is correct |
72 | Correct | 3 ms | 10328 KB | Output is correct |
73 | Correct | 3 ms | 10332 KB | Output is correct |
74 | Correct | 3 ms | 10332 KB | Output is correct |
75 | Correct | 3 ms | 10332 KB | Output is correct |
76 | Correct | 3 ms | 10332 KB | Output is correct |
77 | Correct | 3 ms | 10328 KB | Output is correct |
78 | Correct | 2 ms | 10328 KB | Output is correct |
79 | Correct | 868 ms | 106920 KB | Output is correct |
80 | Correct | 635 ms | 105976 KB | Output is correct |
81 | Correct | 659 ms | 105952 KB | Output is correct |
82 | Correct | 572 ms | 102736 KB | Output is correct |
83 | Correct | 477 ms | 102992 KB | Output is correct |
84 | Correct | 464 ms | 103528 KB | Output is correct |
85 | Correct | 406 ms | 103556 KB | Output is correct |
86 | Correct | 870 ms | 105372 KB | Output is correct |
87 | Correct | 631 ms | 106836 KB | Output is correct |
88 | Correct | 792 ms | 102536 KB | Output is correct |
89 | Correct | 476 ms | 103336 KB | Output is correct |
90 | Correct | 342 ms | 104276 KB | Output is correct |
91 | Correct | 347 ms | 105112 KB | Output is correct |
92 | Correct | 3 ms | 10332 KB | Output is correct |
93 | Correct | 3 ms | 10332 KB | Output is correct |
94 | Correct | 3 ms | 10472 KB | Output is correct |
95 | Correct | 3 ms | 10332 KB | Output is correct |
96 | Correct | 3 ms | 10328 KB | Output is correct |
97 | Correct | 2 ms | 10332 KB | Output is correct |
98 | Correct | 898 ms | 104232 KB | Output is correct |
99 | Correct | 623 ms | 105288 KB | Output is correct |
100 | Correct | 665 ms | 106592 KB | Output is correct |
101 | Correct | 564 ms | 104528 KB | Output is correct |
102 | Correct | 488 ms | 104584 KB | Output is correct |
103 | Correct | 476 ms | 104276 KB | Output is correct |
104 | Correct | 421 ms | 104608 KB | Output is correct |
105 | Correct | 869 ms | 109316 KB | Output is correct |
106 | Correct | 626 ms | 107600 KB | Output is correct |
107 | Correct | 792 ms | 105212 KB | Output is correct |
108 | Correct | 443 ms | 103504 KB | Output is correct |
109 | Correct | 349 ms | 104388 KB | Output is correct |
110 | Correct | 342 ms | 105300 KB | Output is correct |
111 | Correct | 3 ms | 10332 KB | Output is correct |
112 | Correct | 3 ms | 10332 KB | Output is correct |
113 | Correct | 3 ms | 10332 KB | Output is correct |
114 | Correct | 3 ms | 10480 KB | Output is correct |
115 | Correct | 3 ms | 10328 KB | Output is correct |
116 | Correct | 797 ms | 103792 KB | Output is correct |
117 | Correct | 489 ms | 106036 KB | Output is correct |
118 | Correct | 687 ms | 109940 KB | Output is correct |
119 | Correct | 604 ms | 105836 KB | Output is correct |
120 | Correct | 514 ms | 105716 KB | Output is correct |
121 | Correct | 512 ms | 106320 KB | Output is correct |
122 | Correct | 438 ms | 106460 KB | Output is correct |
123 | Correct | 869 ms | 108904 KB | Output is correct |
124 | Correct | 635 ms | 108224 KB | Output is correct |
125 | Correct | 765 ms | 105096 KB | Output is correct |
126 | Correct | 545 ms | 106356 KB | Output is correct |
127 | Correct | 520 ms | 106444 KB | Output is correct |
128 | Correct | 458 ms | 107232 KB | Output is correct |
129 | Correct | 474 ms | 108248 KB | Output is correct |