Submission #683193

# Submission time Handle Problem Language Result Execution time Memory
683193 2023-01-17T22:45:27 Z arnold518 Sprinkler (JOI22_sprinkler) C++17
100 / 100
872 ms 94360 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5+100;

int N, Q;
ll L, H[MAXN+10];
vector<int> adj[MAXN+10];

int par[MAXN+10];
ll val[MAXN+10][41];

void dfs(int now, int bef)
{
	par[now]=bef;
	for(int nxt : adj[now])
	{
		if(nxt==bef) continue;
		dfs(nxt, now);
	}
}

int main()
{
	fill(&val[0][0], &val[0][0]+sizeof(val)/sizeof(ll), 1);
	scanf("%d%lld", &N, &L);
	for(int i=1; i<N; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1; i<=N; i++) sort(adj[i].begin(), adj[i].end());
	for(int i=1; i<=N; i++) scanf("%lld", &H[i]);
	dfs(1, 0);
	for(int i=1; i<=50; i++) par[N+i]=N+i+1;
	par[1]=N+1;
	par[N+50]=0;

	scanf("%d", &Q);
	while(Q--)
	{
		int t;
		scanf("%d", &t);
		if(t==1)
		{
			int x, d, w;
			scanf("%d%d%d", &x, &d, &w);
			
			int now=x;
			while(now && d>=0)
			{
				if(d>0) (val[now][d-1]*=w)%=L;
				(val[now][d]*=w)%=L;

				d--;
				now=par[now];
			}
		}
		else
		{
			int x;
			scanf("%d", &x);
			int now=x, d=0;
			ll ans=H[now];
			while(now && d<=40)
			{
				(ans*=val[now][d])%=L;

				d++;
				now=par[now];
			}
			printf("%lld\n", ans);
		}
	}
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%lld", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
sprinkler.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:39:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  for(int i=1; i<=N; i++) scanf("%lld", &H[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
sprinkler.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
sprinkler.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |    scanf("%d%d%d", &x, &d, &w);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:68:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 69220 KB Output is correct
2 Correct 27 ms 69220 KB Output is correct
3 Correct 28 ms 69120 KB Output is correct
4 Correct 31 ms 69324 KB Output is correct
5 Correct 29 ms 69204 KB Output is correct
6 Correct 28 ms 69208 KB Output is correct
7 Correct 28 ms 69232 KB Output is correct
8 Correct 29 ms 69232 KB Output is correct
9 Correct 28 ms 69176 KB Output is correct
10 Correct 28 ms 69204 KB Output is correct
11 Correct 29 ms 69128 KB Output is correct
12 Correct 34 ms 69220 KB Output is correct
13 Correct 32 ms 69196 KB Output is correct
14 Correct 32 ms 69180 KB Output is correct
15 Correct 29 ms 69184 KB Output is correct
16 Correct 29 ms 69204 KB Output is correct
17 Correct 29 ms 69212 KB Output is correct
18 Correct 29 ms 69144 KB Output is correct
19 Correct 29 ms 69172 KB Output is correct
20 Correct 36 ms 69180 KB Output is correct
21 Correct 29 ms 69100 KB Output is correct
22 Correct 28 ms 69144 KB Output is correct
23 Correct 32 ms 69232 KB Output is correct
24 Correct 33 ms 69208 KB Output is correct
25 Correct 30 ms 69204 KB Output is correct
26 Correct 36 ms 69140 KB Output is correct
27 Correct 31 ms 69180 KB Output is correct
28 Correct 36 ms 69132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 69204 KB Output is correct
2 Correct 590 ms 89732 KB Output is correct
3 Correct 404 ms 90244 KB Output is correct
4 Correct 522 ms 92984 KB Output is correct
5 Correct 523 ms 90100 KB Output is correct
6 Correct 434 ms 89632 KB Output is correct
7 Correct 428 ms 90256 KB Output is correct
8 Correct 337 ms 90648 KB Output is correct
9 Correct 586 ms 94144 KB Output is correct
10 Correct 446 ms 94288 KB Output is correct
11 Correct 583 ms 89660 KB Output is correct
12 Correct 395 ms 90132 KB Output is correct
13 Correct 321 ms 90412 KB Output is correct
14 Correct 290 ms 90928 KB Output is correct
15 Correct 311 ms 90304 KB Output is correct
16 Correct 293 ms 90836 KB Output is correct
17 Correct 314 ms 91376 KB Output is correct
18 Correct 32 ms 69148 KB Output is correct
19 Correct 29 ms 69148 KB Output is correct
20 Correct 30 ms 69188 KB Output is correct
21 Correct 29 ms 69208 KB Output is correct
22 Correct 29 ms 69204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 69204 KB Output is correct
2 Correct 590 ms 89732 KB Output is correct
3 Correct 404 ms 90244 KB Output is correct
4 Correct 522 ms 92984 KB Output is correct
5 Correct 523 ms 90100 KB Output is correct
6 Correct 434 ms 89632 KB Output is correct
7 Correct 428 ms 90256 KB Output is correct
8 Correct 337 ms 90648 KB Output is correct
9 Correct 586 ms 94144 KB Output is correct
10 Correct 446 ms 94288 KB Output is correct
11 Correct 583 ms 89660 KB Output is correct
12 Correct 395 ms 90132 KB Output is correct
13 Correct 321 ms 90412 KB Output is correct
14 Correct 290 ms 90928 KB Output is correct
15 Correct 311 ms 90304 KB Output is correct
16 Correct 293 ms 90836 KB Output is correct
17 Correct 314 ms 91376 KB Output is correct
18 Correct 32 ms 69148 KB Output is correct
19 Correct 29 ms 69148 KB Output is correct
20 Correct 30 ms 69188 KB Output is correct
21 Correct 29 ms 69208 KB Output is correct
22 Correct 29 ms 69204 KB Output is correct
23 Correct 37 ms 69152 KB Output is correct
24 Correct 587 ms 89664 KB Output is correct
25 Correct 400 ms 90344 KB Output is correct
26 Correct 557 ms 94360 KB Output is correct
27 Correct 565 ms 89872 KB Output is correct
28 Correct 409 ms 90000 KB Output is correct
29 Correct 383 ms 89728 KB Output is correct
30 Correct 362 ms 90776 KB Output is correct
31 Correct 692 ms 92864 KB Output is correct
32 Correct 406 ms 94300 KB Output is correct
33 Correct 574 ms 89644 KB Output is correct
34 Correct 449 ms 90116 KB Output is correct
35 Correct 32 ms 69280 KB Output is correct
36 Correct 30 ms 69200 KB Output is correct
37 Correct 34 ms 69132 KB Output is correct
38 Correct 35 ms 69180 KB Output is correct
39 Correct 34 ms 69196 KB Output is correct
40 Correct 30 ms 69188 KB Output is correct
41 Correct 30 ms 69204 KB Output is correct
42 Correct 30 ms 69132 KB Output is correct
43 Correct 30 ms 69180 KB Output is correct
44 Correct 33 ms 69152 KB Output is correct
45 Correct 29 ms 69208 KB Output is correct
46 Correct 29 ms 69148 KB Output is correct
47 Correct 30 ms 69228 KB Output is correct
48 Correct 38 ms 69108 KB Output is correct
49 Correct 37 ms 69160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 69204 KB Output is correct
2 Correct 672 ms 91252 KB Output is correct
3 Correct 742 ms 90840 KB Output is correct
4 Correct 644 ms 90532 KB Output is correct
5 Correct 560 ms 86972 KB Output is correct
6 Correct 473 ms 87112 KB Output is correct
7 Correct 432 ms 87216 KB Output is correct
8 Correct 397 ms 87736 KB Output is correct
9 Correct 725 ms 89924 KB Output is correct
10 Correct 872 ms 91376 KB Output is correct
11 Correct 776 ms 86516 KB Output is correct
12 Correct 806 ms 87388 KB Output is correct
13 Correct 465 ms 88400 KB Output is correct
14 Correct 586 ms 88996 KB Output is correct
15 Correct 32 ms 69216 KB Output is correct
16 Correct 34 ms 69220 KB Output is correct
17 Correct 32 ms 69216 KB Output is correct
18 Correct 32 ms 69244 KB Output is correct
19 Correct 32 ms 69148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 69104 KB Output is correct
2 Correct 791 ms 92408 KB Output is correct
3 Correct 791 ms 90168 KB Output is correct
4 Correct 618 ms 91168 KB Output is correct
5 Correct 588 ms 88552 KB Output is correct
6 Correct 447 ms 88800 KB Output is correct
7 Correct 422 ms 88384 KB Output is correct
8 Correct 385 ms 88768 KB Output is correct
9 Correct 683 ms 93772 KB Output is correct
10 Correct 797 ms 92120 KB Output is correct
11 Correct 632 ms 89308 KB Output is correct
12 Correct 627 ms 87800 KB Output is correct
13 Correct 496 ms 88468 KB Output is correct
14 Correct 456 ms 89124 KB Output is correct
15 Correct 33 ms 69204 KB Output is correct
16 Correct 34 ms 69104 KB Output is correct
17 Correct 32 ms 69184 KB Output is correct
18 Correct 32 ms 69160 KB Output is correct
19 Correct 31 ms 69288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 69220 KB Output is correct
2 Correct 27 ms 69220 KB Output is correct
3 Correct 28 ms 69120 KB Output is correct
4 Correct 31 ms 69324 KB Output is correct
5 Correct 29 ms 69204 KB Output is correct
6 Correct 28 ms 69208 KB Output is correct
7 Correct 28 ms 69232 KB Output is correct
8 Correct 29 ms 69232 KB Output is correct
9 Correct 28 ms 69176 KB Output is correct
10 Correct 28 ms 69204 KB Output is correct
11 Correct 29 ms 69128 KB Output is correct
12 Correct 34 ms 69220 KB Output is correct
13 Correct 32 ms 69196 KB Output is correct
14 Correct 32 ms 69180 KB Output is correct
15 Correct 29 ms 69184 KB Output is correct
16 Correct 29 ms 69204 KB Output is correct
17 Correct 29 ms 69212 KB Output is correct
18 Correct 29 ms 69144 KB Output is correct
19 Correct 29 ms 69172 KB Output is correct
20 Correct 36 ms 69180 KB Output is correct
21 Correct 29 ms 69100 KB Output is correct
22 Correct 28 ms 69144 KB Output is correct
23 Correct 32 ms 69232 KB Output is correct
24 Correct 33 ms 69208 KB Output is correct
25 Correct 30 ms 69204 KB Output is correct
26 Correct 36 ms 69140 KB Output is correct
27 Correct 31 ms 69180 KB Output is correct
28 Correct 36 ms 69132 KB Output is correct
29 Correct 28 ms 69204 KB Output is correct
30 Correct 590 ms 89732 KB Output is correct
31 Correct 404 ms 90244 KB Output is correct
32 Correct 522 ms 92984 KB Output is correct
33 Correct 523 ms 90100 KB Output is correct
34 Correct 434 ms 89632 KB Output is correct
35 Correct 428 ms 90256 KB Output is correct
36 Correct 337 ms 90648 KB Output is correct
37 Correct 586 ms 94144 KB Output is correct
38 Correct 446 ms 94288 KB Output is correct
39 Correct 583 ms 89660 KB Output is correct
40 Correct 395 ms 90132 KB Output is correct
41 Correct 321 ms 90412 KB Output is correct
42 Correct 290 ms 90928 KB Output is correct
43 Correct 311 ms 90304 KB Output is correct
44 Correct 293 ms 90836 KB Output is correct
45 Correct 314 ms 91376 KB Output is correct
46 Correct 32 ms 69148 KB Output is correct
47 Correct 29 ms 69148 KB Output is correct
48 Correct 30 ms 69188 KB Output is correct
49 Correct 29 ms 69208 KB Output is correct
50 Correct 29 ms 69204 KB Output is correct
51 Correct 37 ms 69152 KB Output is correct
52 Correct 587 ms 89664 KB Output is correct
53 Correct 400 ms 90344 KB Output is correct
54 Correct 557 ms 94360 KB Output is correct
55 Correct 565 ms 89872 KB Output is correct
56 Correct 409 ms 90000 KB Output is correct
57 Correct 383 ms 89728 KB Output is correct
58 Correct 362 ms 90776 KB Output is correct
59 Correct 692 ms 92864 KB Output is correct
60 Correct 406 ms 94300 KB Output is correct
61 Correct 574 ms 89644 KB Output is correct
62 Correct 449 ms 90116 KB Output is correct
63 Correct 32 ms 69280 KB Output is correct
64 Correct 30 ms 69200 KB Output is correct
65 Correct 34 ms 69132 KB Output is correct
66 Correct 35 ms 69180 KB Output is correct
67 Correct 34 ms 69196 KB Output is correct
68 Correct 30 ms 69188 KB Output is correct
69 Correct 30 ms 69204 KB Output is correct
70 Correct 30 ms 69132 KB Output is correct
71 Correct 30 ms 69180 KB Output is correct
72 Correct 33 ms 69152 KB Output is correct
73 Correct 29 ms 69208 KB Output is correct
74 Correct 29 ms 69148 KB Output is correct
75 Correct 30 ms 69228 KB Output is correct
76 Correct 38 ms 69108 KB Output is correct
77 Correct 37 ms 69160 KB Output is correct
78 Correct 30 ms 69204 KB Output is correct
79 Correct 672 ms 91252 KB Output is correct
80 Correct 742 ms 90840 KB Output is correct
81 Correct 644 ms 90532 KB Output is correct
82 Correct 560 ms 86972 KB Output is correct
83 Correct 473 ms 87112 KB Output is correct
84 Correct 432 ms 87216 KB Output is correct
85 Correct 397 ms 87736 KB Output is correct
86 Correct 725 ms 89924 KB Output is correct
87 Correct 872 ms 91376 KB Output is correct
88 Correct 776 ms 86516 KB Output is correct
89 Correct 806 ms 87388 KB Output is correct
90 Correct 465 ms 88400 KB Output is correct
91 Correct 586 ms 88996 KB Output is correct
92 Correct 32 ms 69216 KB Output is correct
93 Correct 34 ms 69220 KB Output is correct
94 Correct 32 ms 69216 KB Output is correct
95 Correct 32 ms 69244 KB Output is correct
96 Correct 32 ms 69148 KB Output is correct
97 Correct 32 ms 69104 KB Output is correct
98 Correct 791 ms 92408 KB Output is correct
99 Correct 791 ms 90168 KB Output is correct
100 Correct 618 ms 91168 KB Output is correct
101 Correct 588 ms 88552 KB Output is correct
102 Correct 447 ms 88800 KB Output is correct
103 Correct 422 ms 88384 KB Output is correct
104 Correct 385 ms 88768 KB Output is correct
105 Correct 683 ms 93772 KB Output is correct
106 Correct 797 ms 92120 KB Output is correct
107 Correct 632 ms 89308 KB Output is correct
108 Correct 627 ms 87800 KB Output is correct
109 Correct 496 ms 88468 KB Output is correct
110 Correct 456 ms 89124 KB Output is correct
111 Correct 33 ms 69204 KB Output is correct
112 Correct 34 ms 69104 KB Output is correct
113 Correct 32 ms 69184 KB Output is correct
114 Correct 32 ms 69160 KB Output is correct
115 Correct 31 ms 69288 KB Output is correct
116 Correct 663 ms 87664 KB Output is correct
117 Correct 762 ms 90296 KB Output is correct
118 Correct 622 ms 94188 KB Output is correct
119 Correct 595 ms 89972 KB Output is correct
120 Correct 501 ms 89676 KB Output is correct
121 Correct 479 ms 90476 KB Output is correct
122 Correct 420 ms 90644 KB Output is correct
123 Correct 736 ms 93300 KB Output is correct
124 Correct 782 ms 92812 KB Output is correct
125 Correct 619 ms 88824 KB Output is correct
126 Correct 648 ms 90300 KB Output is correct
127 Correct 743 ms 90608 KB Output is correct
128 Correct 553 ms 91340 KB Output is correct
129 Correct 579 ms 91956 KB Output is correct