Submission #877441

# Submission time Handle Problem Language Result Execution time Memory
877441 2023-11-23T08:40:10 Z serkanrashid Sprinkler (JOI22_sprinkler) C++14
100 / 100
674 ms 97808 KB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

const int maxn = 2*1e5+5;

long long n,l,q;
long long type,x,d,w;
long long h[maxn],par[maxn];
long long dp[maxn][42];
vector<int>g[maxn];
long long ans;

void dfs(int beg, int p)
{
    par[beg] = p;
    for(int nb:g[beg])
    {
        if(nb!=p) dfs(nb,beg);
    }
}

void dfs1(int beg, int d, long long w)
{
    if(d<0) return;
    dp[beg][d] = (dp[beg][d]*w)%l;
    d--;
    if(d<0) return;
    dp[beg][d] = (dp[beg][d]*w)%l;
    if(par[beg]==beg) d--;
    dfs1(par[beg],d,w);
}

void dfs2(int beg, int d)
{
    if(d>40) return;
    ans = (ans*dp[beg][d])%l;
    if(beg!=par[beg]) dfs2(par[beg],d+1);
}

void read()
{
    cin >> n >> l;
    for(int i=1;i<=n;i++)
    {
        for(int z=0;z<=41;z++) dp[i][z] = 1;
    }
    int a,b;
    for(int i=1;i<n;i++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=1;i<=n;i++) cin >> h[i];
    dfs(1,1);
    cin >> q;
    for(int i=1;i<=q;i++)
    {
        cin >> type >> x;
        /*for(int j=1;j<=n;j++)
        {
            cout << j << "->";
            for(int z=0;z<=n;z++)
            {
                cout << " " << dp[j][z];
            }
            cout << endl;
        }*/
        if(type==2)
        {
            ans = h[x];
            dfs2(x,0);
            cout << ans << endl;

        }
        else
        {
            cin >> d >> w;
            dfs1(x,d,w);
        }
        /*for(int j=1;j<=n;j++)
        {
            cout << j << "->";
            for(int z=0;z<=n;z++)
            {
                cout << " " << dp[j][z];
            }
            cout << endl;
        }
        cout << "+++++++++" << " " << "end query" << endl;*/
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read();
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8808 KB Output is correct
3 Correct 1 ms 8792 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8812 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8860 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 340 ms 83796 KB Output is correct
3 Correct 271 ms 92636 KB Output is correct
4 Correct 384 ms 95868 KB Output is correct
5 Correct 305 ms 92232 KB Output is correct
6 Correct 234 ms 91872 KB Output is correct
7 Correct 225 ms 92548 KB Output is correct
8 Correct 199 ms 93080 KB Output is correct
9 Correct 457 ms 97360 KB Output is correct
10 Correct 259 ms 97628 KB Output is correct
11 Correct 376 ms 92016 KB Output is correct
12 Correct 237 ms 92500 KB Output is correct
13 Correct 170 ms 92792 KB Output is correct
14 Correct 173 ms 93200 KB Output is correct
15 Correct 187 ms 92744 KB Output is correct
16 Correct 174 ms 93268 KB Output is correct
17 Correct 188 ms 93684 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 340 ms 83796 KB Output is correct
3 Correct 271 ms 92636 KB Output is correct
4 Correct 384 ms 95868 KB Output is correct
5 Correct 305 ms 92232 KB Output is correct
6 Correct 234 ms 91872 KB Output is correct
7 Correct 225 ms 92548 KB Output is correct
8 Correct 199 ms 93080 KB Output is correct
9 Correct 457 ms 97360 KB Output is correct
10 Correct 259 ms 97628 KB Output is correct
11 Correct 376 ms 92016 KB Output is correct
12 Correct 237 ms 92500 KB Output is correct
13 Correct 170 ms 92792 KB Output is correct
14 Correct 173 ms 93200 KB Output is correct
15 Correct 187 ms 92744 KB Output is correct
16 Correct 174 ms 93268 KB Output is correct
17 Correct 188 ms 93684 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8808 KB Output is correct
24 Correct 376 ms 92140 KB Output is correct
25 Correct 257 ms 92528 KB Output is correct
26 Correct 403 ms 97788 KB Output is correct
27 Correct 322 ms 92280 KB Output is correct
28 Correct 251 ms 92464 KB Output is correct
29 Correct 249 ms 92220 KB Output is correct
30 Correct 199 ms 93128 KB Output is correct
31 Correct 487 ms 96176 KB Output is correct
32 Correct 301 ms 97564 KB Output is correct
33 Correct 394 ms 92136 KB Output is correct
34 Correct 273 ms 92564 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 2 ms 8796 KB Output is correct
38 Correct 2 ms 8844 KB Output is correct
39 Correct 2 ms 8796 KB Output is correct
40 Correct 2 ms 8796 KB Output is correct
41 Correct 2 ms 8796 KB Output is correct
42 Correct 2 ms 8796 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 2 ms 8796 KB Output is correct
45 Correct 2 ms 8796 KB Output is correct
46 Correct 2 ms 8796 KB Output is correct
47 Correct 2 ms 8868 KB Output is correct
48 Correct 2 ms 8796 KB Output is correct
49 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 521 ms 90080 KB Output is correct
3 Correct 659 ms 93960 KB Output is correct
4 Correct 462 ms 93776 KB Output is correct
5 Correct 359 ms 89428 KB Output is correct
6 Correct 260 ms 89456 KB Output is correct
7 Correct 257 ms 89684 KB Output is correct
8 Correct 201 ms 90160 KB Output is correct
9 Correct 527 ms 93216 KB Output is correct
10 Correct 637 ms 95064 KB Output is correct
11 Correct 379 ms 88932 KB Output is correct
12 Correct 424 ms 89988 KB Output is correct
13 Correct 319 ms 90704 KB Output is correct
14 Correct 325 ms 91312 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8848 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 536 ms 90860 KB Output is correct
3 Correct 641 ms 93108 KB Output is correct
4 Correct 515 ms 94288 KB Output is correct
5 Correct 358 ms 90912 KB Output is correct
6 Correct 285 ms 91200 KB Output is correct
7 Correct 263 ms 90704 KB Output is correct
8 Correct 208 ms 91080 KB Output is correct
9 Correct 505 ms 96852 KB Output is correct
10 Correct 656 ms 95268 KB Output is correct
11 Correct 412 ms 91680 KB Output is correct
12 Correct 434 ms 90196 KB Output is correct
13 Correct 339 ms 90904 KB Output is correct
14 Correct 315 ms 91472 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8808 KB Output is correct
3 Correct 1 ms 8792 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8812 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8860 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 1 ms 8792 KB Output is correct
30 Correct 340 ms 83796 KB Output is correct
31 Correct 271 ms 92636 KB Output is correct
32 Correct 384 ms 95868 KB Output is correct
33 Correct 305 ms 92232 KB Output is correct
34 Correct 234 ms 91872 KB Output is correct
35 Correct 225 ms 92548 KB Output is correct
36 Correct 199 ms 93080 KB Output is correct
37 Correct 457 ms 97360 KB Output is correct
38 Correct 259 ms 97628 KB Output is correct
39 Correct 376 ms 92016 KB Output is correct
40 Correct 237 ms 92500 KB Output is correct
41 Correct 170 ms 92792 KB Output is correct
42 Correct 173 ms 93200 KB Output is correct
43 Correct 187 ms 92744 KB Output is correct
44 Correct 174 ms 93268 KB Output is correct
45 Correct 188 ms 93684 KB Output is correct
46 Correct 2 ms 8796 KB Output is correct
47 Correct 2 ms 8796 KB Output is correct
48 Correct 2 ms 8796 KB Output is correct
49 Correct 2 ms 8796 KB Output is correct
50 Correct 2 ms 8796 KB Output is correct
51 Correct 2 ms 8808 KB Output is correct
52 Correct 376 ms 92140 KB Output is correct
53 Correct 257 ms 92528 KB Output is correct
54 Correct 403 ms 97788 KB Output is correct
55 Correct 322 ms 92280 KB Output is correct
56 Correct 251 ms 92464 KB Output is correct
57 Correct 249 ms 92220 KB Output is correct
58 Correct 199 ms 93128 KB Output is correct
59 Correct 487 ms 96176 KB Output is correct
60 Correct 301 ms 97564 KB Output is correct
61 Correct 394 ms 92136 KB Output is correct
62 Correct 273 ms 92564 KB Output is correct
63 Correct 2 ms 8792 KB Output is correct
64 Correct 2 ms 8796 KB Output is correct
65 Correct 2 ms 8796 KB Output is correct
66 Correct 2 ms 8844 KB Output is correct
67 Correct 2 ms 8796 KB Output is correct
68 Correct 2 ms 8796 KB Output is correct
69 Correct 2 ms 8796 KB Output is correct
70 Correct 2 ms 8796 KB Output is correct
71 Correct 2 ms 8796 KB Output is correct
72 Correct 2 ms 8796 KB Output is correct
73 Correct 2 ms 8796 KB Output is correct
74 Correct 2 ms 8796 KB Output is correct
75 Correct 2 ms 8868 KB Output is correct
76 Correct 2 ms 8796 KB Output is correct
77 Correct 2 ms 8796 KB Output is correct
78 Correct 1 ms 8796 KB Output is correct
79 Correct 521 ms 90080 KB Output is correct
80 Correct 659 ms 93960 KB Output is correct
81 Correct 462 ms 93776 KB Output is correct
82 Correct 359 ms 89428 KB Output is correct
83 Correct 260 ms 89456 KB Output is correct
84 Correct 257 ms 89684 KB Output is correct
85 Correct 201 ms 90160 KB Output is correct
86 Correct 527 ms 93216 KB Output is correct
87 Correct 637 ms 95064 KB Output is correct
88 Correct 379 ms 88932 KB Output is correct
89 Correct 424 ms 89988 KB Output is correct
90 Correct 319 ms 90704 KB Output is correct
91 Correct 325 ms 91312 KB Output is correct
92 Correct 2 ms 8796 KB Output is correct
93 Correct 2 ms 8848 KB Output is correct
94 Correct 2 ms 8796 KB Output is correct
95 Correct 2 ms 8792 KB Output is correct
96 Correct 2 ms 8792 KB Output is correct
97 Correct 1 ms 8796 KB Output is correct
98 Correct 536 ms 90860 KB Output is correct
99 Correct 641 ms 93108 KB Output is correct
100 Correct 515 ms 94288 KB Output is correct
101 Correct 358 ms 90912 KB Output is correct
102 Correct 285 ms 91200 KB Output is correct
103 Correct 263 ms 90704 KB Output is correct
104 Correct 208 ms 91080 KB Output is correct
105 Correct 505 ms 96852 KB Output is correct
106 Correct 656 ms 95268 KB Output is correct
107 Correct 412 ms 91680 KB Output is correct
108 Correct 434 ms 90196 KB Output is correct
109 Correct 339 ms 90904 KB Output is correct
110 Correct 315 ms 91472 KB Output is correct
111 Correct 2 ms 8792 KB Output is correct
112 Correct 2 ms 8792 KB Output is correct
113 Correct 2 ms 8796 KB Output is correct
114 Correct 2 ms 8796 KB Output is correct
115 Correct 2 ms 8796 KB Output is correct
116 Correct 429 ms 90140 KB Output is correct
117 Correct 488 ms 92496 KB Output is correct
118 Correct 536 ms 97808 KB Output is correct
119 Correct 457 ms 92332 KB Output is correct
120 Correct 333 ms 91880 KB Output is correct
121 Correct 321 ms 92840 KB Output is correct
122 Correct 252 ms 92928 KB Output is correct
123 Correct 573 ms 96788 KB Output is correct
124 Correct 674 ms 95752 KB Output is correct
125 Correct 447 ms 91220 KB Output is correct
126 Correct 527 ms 92500 KB Output is correct
127 Correct 532 ms 93032 KB Output is correct
128 Correct 437 ms 93780 KB Output is correct
129 Correct 454 ms 94260 KB Output is correct