Submission #654209

# Submission time Handle Problem Language Result Execution time Memory
654209 2022-10-30T11:06:27 Z InternetPerson10 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1070 ms 97148 KB
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

ll MOD;

vector<vector<int>> adj;
vector<int> par;
ll mul[200001][41];

void root(int x = 0, int p = 0) {
    par[x] = p;
    for(auto it = adj[x].begin(); it != adj[x].end(); it++) {
        if(*it == p) {
            adj[x].erase(it);
            break;
        }
    }
    for(int ch : adj[x]) {
        root(ch, x);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n >> MOD;
    adj.resize(n);
    par.resize(n);
    for(int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    root();
    for(int i = 0; i < n; i++) {
        cin >> mul[i][0];
        for(int j = 1; j <= 40; j++) {
            mul[i][j] = 1;
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int x, d, w;
            cin >> x >> d >> w;
            x--;
            while(x != par[x]) {
                if(d >= 0) {
                    mul[x][d] *= w;
                    mul[x][d] %= MOD;
                }
                if(d >= 1) {
                    mul[x][d-1] *= w;
                    mul[x][d-1] %= MOD;
                }
                x = par[x];
                d--;
                if(d < 0) break;
            }
            if(d >= 0) {
                mul[x][d] *= w;
                mul[x][d] %= MOD;
            }
            if(d >= 1) {
                mul[x][d-1] *= w;
                mul[x][d-1] %= MOD;
            }
        }
        if(t == 2) {
            int x;
            cin >> x;
            x--;
            ll ans = 1;
            for(int d = 0; d <= 40; d++) {
                ans *= mul[x][d];
                ans %= MOD;
                if(x == par[x]) d++;
                x = par[x];
            }
            cout << ans << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 493 ms 79936 KB Output is correct
3 Correct 316 ms 76704 KB Output is correct
4 Correct 478 ms 89432 KB Output is correct
5 Correct 463 ms 88400 KB Output is correct
6 Correct 373 ms 87936 KB Output is correct
7 Correct 362 ms 88652 KB Output is correct
8 Correct 297 ms 89184 KB Output is correct
9 Correct 594 ms 97148 KB Output is correct
10 Correct 389 ms 96784 KB Output is correct
11 Correct 513 ms 88224 KB Output is correct
12 Correct 387 ms 88628 KB Output is correct
13 Correct 254 ms 88816 KB Output is correct
14 Correct 258 ms 89312 KB Output is correct
15 Correct 261 ms 88712 KB Output is correct
16 Correct 271 ms 89220 KB Output is correct
17 Correct 284 ms 89728 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 493 ms 79936 KB Output is correct
3 Correct 316 ms 76704 KB Output is correct
4 Correct 478 ms 89432 KB Output is correct
5 Correct 463 ms 88400 KB Output is correct
6 Correct 373 ms 87936 KB Output is correct
7 Correct 362 ms 88652 KB Output is correct
8 Correct 297 ms 89184 KB Output is correct
9 Correct 594 ms 97148 KB Output is correct
10 Correct 389 ms 96784 KB Output is correct
11 Correct 513 ms 88224 KB Output is correct
12 Correct 387 ms 88628 KB Output is correct
13 Correct 254 ms 88816 KB Output is correct
14 Correct 258 ms 89312 KB Output is correct
15 Correct 261 ms 88712 KB Output is correct
16 Correct 271 ms 89220 KB Output is correct
17 Correct 284 ms 89728 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 545 ms 88208 KB Output is correct
25 Correct 380 ms 88652 KB Output is correct
26 Correct 497 ms 97004 KB Output is correct
27 Correct 485 ms 88288 KB Output is correct
28 Correct 370 ms 88508 KB Output is correct
29 Correct 393 ms 88300 KB Output is correct
30 Correct 337 ms 89160 KB Output is correct
31 Correct 579 ms 94376 KB Output is correct
32 Correct 441 ms 96816 KB Output is correct
33 Correct 607 ms 88060 KB Output is correct
34 Correct 454 ms 88548 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 380 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1070 ms 89624 KB Output is correct
3 Correct 956 ms 92592 KB Output is correct
4 Correct 679 ms 92512 KB Output is correct
5 Correct 602 ms 85500 KB Output is correct
6 Correct 415 ms 85628 KB Output is correct
7 Correct 407 ms 85564 KB Output is correct
8 Correct 311 ms 86212 KB Output is correct
9 Correct 778 ms 91428 KB Output is correct
10 Correct 803 ms 93848 KB Output is correct
11 Correct 637 ms 85020 KB Output is correct
12 Correct 731 ms 85924 KB Output is correct
13 Correct 499 ms 86764 KB Output is correct
14 Correct 501 ms 87328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 755 ms 89300 KB Output is correct
3 Correct 892 ms 90768 KB Output is correct
4 Correct 639 ms 92252 KB Output is correct
5 Correct 685 ms 87004 KB Output is correct
6 Correct 447 ms 87052 KB Output is correct
7 Correct 429 ms 86860 KB Output is correct
8 Correct 308 ms 87156 KB Output is correct
9 Correct 685 ms 96040 KB Output is correct
10 Correct 879 ms 94660 KB Output is correct
11 Correct 674 ms 87724 KB Output is correct
12 Correct 804 ms 86216 KB Output is correct
13 Correct 487 ms 86932 KB Output is correct
14 Correct 523 ms 87472 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 493 ms 79936 KB Output is correct
31 Correct 316 ms 76704 KB Output is correct
32 Correct 478 ms 89432 KB Output is correct
33 Correct 463 ms 88400 KB Output is correct
34 Correct 373 ms 87936 KB Output is correct
35 Correct 362 ms 88652 KB Output is correct
36 Correct 297 ms 89184 KB Output is correct
37 Correct 594 ms 97148 KB Output is correct
38 Correct 389 ms 96784 KB Output is correct
39 Correct 513 ms 88224 KB Output is correct
40 Correct 387 ms 88628 KB Output is correct
41 Correct 254 ms 88816 KB Output is correct
42 Correct 258 ms 89312 KB Output is correct
43 Correct 261 ms 88712 KB Output is correct
44 Correct 271 ms 89220 KB Output is correct
45 Correct 284 ms 89728 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 545 ms 88208 KB Output is correct
53 Correct 380 ms 88652 KB Output is correct
54 Correct 497 ms 97004 KB Output is correct
55 Correct 485 ms 88288 KB Output is correct
56 Correct 370 ms 88508 KB Output is correct
57 Correct 393 ms 88300 KB Output is correct
58 Correct 337 ms 89160 KB Output is correct
59 Correct 579 ms 94376 KB Output is correct
60 Correct 441 ms 96816 KB Output is correct
61 Correct 607 ms 88060 KB Output is correct
62 Correct 454 ms 88548 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 380 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 332 KB Output is correct
77 Correct 1 ms 336 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1070 ms 89624 KB Output is correct
80 Correct 956 ms 92592 KB Output is correct
81 Correct 679 ms 92512 KB Output is correct
82 Correct 602 ms 85500 KB Output is correct
83 Correct 415 ms 85628 KB Output is correct
84 Correct 407 ms 85564 KB Output is correct
85 Correct 311 ms 86212 KB Output is correct
86 Correct 778 ms 91428 KB Output is correct
87 Correct 803 ms 93848 KB Output is correct
88 Correct 637 ms 85020 KB Output is correct
89 Correct 731 ms 85924 KB Output is correct
90 Correct 499 ms 86764 KB Output is correct
91 Correct 501 ms 87328 KB Output is correct
92 Correct 1 ms 212 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 755 ms 89300 KB Output is correct
99 Correct 892 ms 90768 KB Output is correct
100 Correct 639 ms 92252 KB Output is correct
101 Correct 685 ms 87004 KB Output is correct
102 Correct 447 ms 87052 KB Output is correct
103 Correct 429 ms 86860 KB Output is correct
104 Correct 308 ms 87156 KB Output is correct
105 Correct 685 ms 96040 KB Output is correct
106 Correct 879 ms 94660 KB Output is correct
107 Correct 674 ms 87724 KB Output is correct
108 Correct 804 ms 86216 KB Output is correct
109 Correct 487 ms 86932 KB Output is correct
110 Correct 523 ms 87472 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 1 ms 336 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 875 ms 86140 KB Output is correct
117 Correct 850 ms 88744 KB Output is correct
118 Correct 763 ms 96812 KB Output is correct
119 Correct 686 ms 88420 KB Output is correct
120 Correct 549 ms 88036 KB Output is correct
121 Correct 452 ms 88756 KB Output is correct
122 Correct 319 ms 89088 KB Output is correct
123 Correct 621 ms 95540 KB Output is correct
124 Correct 796 ms 93824 KB Output is correct
125 Correct 567 ms 87240 KB Output is correct
126 Correct 658 ms 88636 KB Output is correct
127 Correct 690 ms 89116 KB Output is correct
128 Correct 528 ms 89768 KB Output is correct
129 Correct 537 ms 90216 KB Output is correct