Submission #568311

# Submission time Handle Problem Language Result Execution time Memory
568311 2022-05-25T08:19:45 Z jamielim Sprinkler (JOI22_sprinkler) C++14
100 / 100
1113 ms 113616 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n,q;
ll l;
vector<int> adj[200005];
int h[200005];
int par[20][200005];
ll mult[200005][45];

void dfs(int x,int p){
	par[0][x]=p;
	for(int i:adj[x]){
		if(i==p)continue;
		dfs(i,x);
	}
}

int main(){
	scanf("%d%lld",&n,&l);
	int a,b;
	for(int i=1;i<n;i++){
		scanf("%d%d",&a,&b);
		adj[a].pb(b);adj[b].pb(a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	dfs(1,0);
	for(int i=1;i<20;i++){
		for(int j=1;j<=n;j++){
			par[i][j]=par[i-1][par[i-1][j]];
		}
	}
	for(int i=0;i<=n;i++)for(int j=0;j<45;j++)mult[i][j]=1;
	
	scanf("%d",&q);
	int t,x,d,w;
	while(q--){
		scanf("%d%d",&t,&x);
		if(t==1){
			scanf("%d%d",&d,&w);
			int cur=x;
			for(int i=0;i<=d;i++){
				mult[cur][d-i]*=w;
				mult[cur][d-i]%=l;
				if(d-i-1>=0){
					mult[cur][d-i-1]*=w;
					mult[cur][d-i-1]%=l;
				}
				if(par[0][cur]==0){
					for(int j=d-i-2;j>=0;j--){
						mult[cur][j]*=w;
						mult[cur][j]%=l;
					}
					break;
				}
				cur=par[0][cur];
			}
		}else{
			ll ans=(h[x]*mult[x][0])%l;
			int cur=x;
			for(int i=1;i<=40;i++){
				cur=par[0][cur];
				if(cur==0)break;
				ans*=mult[cur][i];
				ans%=l;
			}
			printf("%lld\n",(ans+l)%l);
		}
	}
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%lld",&n,&l);
      |  ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d",&a,&b);
      |   ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d",&h[i]);
      |   ~~~~~^~~~~~~~~~~~
sprinkler.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
sprinkler.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d",&t,&x);
      |   ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:57:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |    scanf("%d%d",&d,&w);
      |    ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 6 ms 5564 KB Output is correct
5 Correct 4 ms 5580 KB Output is correct
6 Correct 4 ms 5588 KB Output is correct
7 Correct 4 ms 5588 KB Output is correct
8 Correct 4 ms 5588 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5132 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5144 KB Output is correct
17 Correct 5 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 5 ms 5004 KB Output is correct
20 Correct 3 ms 5008 KB Output is correct
21 Correct 4 ms 5204 KB Output is correct
22 Correct 3 ms 4996 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5076 KB Output is correct
2 Correct 631 ms 104276 KB Output is correct
3 Correct 444 ms 101032 KB Output is correct
4 Correct 572 ms 105660 KB Output is correct
5 Correct 516 ms 102624 KB Output is correct
6 Correct 411 ms 102564 KB Output is correct
7 Correct 407 ms 102848 KB Output is correct
8 Correct 345 ms 103244 KB Output is correct
9 Correct 643 ms 108768 KB Output is correct
10 Correct 480 ms 105224 KB Output is correct
11 Correct 591 ms 104544 KB Output is correct
12 Correct 460 ms 101044 KB Output is correct
13 Correct 310 ms 101592 KB Output is correct
14 Correct 336 ms 101688 KB Output is correct
15 Correct 274 ms 100604 KB Output is correct
16 Correct 341 ms 101572 KB Output is correct
17 Correct 368 ms 102244 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5012 KB Output is correct
20 Correct 3 ms 5140 KB Output is correct
21 Correct 3 ms 5136 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5076 KB Output is correct
2 Correct 631 ms 104276 KB Output is correct
3 Correct 444 ms 101032 KB Output is correct
4 Correct 572 ms 105660 KB Output is correct
5 Correct 516 ms 102624 KB Output is correct
6 Correct 411 ms 102564 KB Output is correct
7 Correct 407 ms 102848 KB Output is correct
8 Correct 345 ms 103244 KB Output is correct
9 Correct 643 ms 108768 KB Output is correct
10 Correct 480 ms 105224 KB Output is correct
11 Correct 591 ms 104544 KB Output is correct
12 Correct 460 ms 101044 KB Output is correct
13 Correct 310 ms 101592 KB Output is correct
14 Correct 336 ms 101688 KB Output is correct
15 Correct 274 ms 100604 KB Output is correct
16 Correct 341 ms 101572 KB Output is correct
17 Correct 368 ms 102244 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5012 KB Output is correct
20 Correct 3 ms 5140 KB Output is correct
21 Correct 3 ms 5136 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 588 ms 104100 KB Output is correct
25 Correct 451 ms 101016 KB Output is correct
26 Correct 582 ms 107168 KB Output is correct
27 Correct 530 ms 102640 KB Output is correct
28 Correct 409 ms 103104 KB Output is correct
29 Correct 442 ms 103000 KB Output is correct
30 Correct 362 ms 103624 KB Output is correct
31 Correct 707 ms 107780 KB Output is correct
32 Correct 562 ms 106080 KB Output is correct
33 Correct 726 ms 105416 KB Output is correct
34 Correct 518 ms 102208 KB Output is correct
35 Correct 4 ms 5016 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 5 ms 5028 KB Output is correct
38 Correct 5 ms 5140 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5136 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 4 ms 5136 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 5 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 856 ms 107360 KB Output is correct
3 Correct 1113 ms 106600 KB Output is correct
4 Correct 727 ms 110212 KB Output is correct
5 Correct 663 ms 106732 KB Output is correct
6 Correct 469 ms 106616 KB Output is correct
7 Correct 387 ms 106916 KB Output is correct
8 Correct 340 ms 107260 KB Output is correct
9 Correct 663 ms 110148 KB Output is correct
10 Correct 862 ms 111192 KB Output is correct
11 Correct 649 ms 106444 KB Output is correct
12 Correct 677 ms 107116 KB Output is correct
13 Correct 508 ms 107564 KB Output is correct
14 Correct 489 ms 108704 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5012 KB Output is correct
17 Correct 3 ms 5128 KB Output is correct
18 Correct 3 ms 5136 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 670 ms 108504 KB Output is correct
3 Correct 835 ms 106380 KB Output is correct
4 Correct 606 ms 110840 KB Output is correct
5 Correct 591 ms 108236 KB Output is correct
6 Correct 447 ms 108452 KB Output is correct
7 Correct 448 ms 108184 KB Output is correct
8 Correct 338 ms 108600 KB Output is correct
9 Correct 702 ms 113616 KB Output is correct
10 Correct 825 ms 111436 KB Output is correct
11 Correct 618 ms 109236 KB Output is correct
12 Correct 712 ms 107408 KB Output is correct
13 Correct 493 ms 108476 KB Output is correct
14 Correct 504 ms 109008 KB Output is correct
15 Correct 3 ms 5204 KB Output is correct
16 Correct 4 ms 5008 KB Output is correct
17 Correct 4 ms 5076 KB Output is correct
18 Correct 4 ms 5092 KB Output is correct
19 Correct 4 ms 5136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 6 ms 5564 KB Output is correct
5 Correct 4 ms 5580 KB Output is correct
6 Correct 4 ms 5588 KB Output is correct
7 Correct 4 ms 5588 KB Output is correct
8 Correct 4 ms 5588 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5132 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5144 KB Output is correct
17 Correct 5 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 5 ms 5004 KB Output is correct
20 Correct 3 ms 5008 KB Output is correct
21 Correct 4 ms 5204 KB Output is correct
22 Correct 3 ms 4996 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 4 ms 5076 KB Output is correct
30 Correct 631 ms 104276 KB Output is correct
31 Correct 444 ms 101032 KB Output is correct
32 Correct 572 ms 105660 KB Output is correct
33 Correct 516 ms 102624 KB Output is correct
34 Correct 411 ms 102564 KB Output is correct
35 Correct 407 ms 102848 KB Output is correct
36 Correct 345 ms 103244 KB Output is correct
37 Correct 643 ms 108768 KB Output is correct
38 Correct 480 ms 105224 KB Output is correct
39 Correct 591 ms 104544 KB Output is correct
40 Correct 460 ms 101044 KB Output is correct
41 Correct 310 ms 101592 KB Output is correct
42 Correct 336 ms 101688 KB Output is correct
43 Correct 274 ms 100604 KB Output is correct
44 Correct 341 ms 101572 KB Output is correct
45 Correct 368 ms 102244 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5012 KB Output is correct
48 Correct 3 ms 5140 KB Output is correct
49 Correct 3 ms 5136 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 4 ms 5076 KB Output is correct
52 Correct 588 ms 104100 KB Output is correct
53 Correct 451 ms 101016 KB Output is correct
54 Correct 582 ms 107168 KB Output is correct
55 Correct 530 ms 102640 KB Output is correct
56 Correct 409 ms 103104 KB Output is correct
57 Correct 442 ms 103000 KB Output is correct
58 Correct 362 ms 103624 KB Output is correct
59 Correct 707 ms 107780 KB Output is correct
60 Correct 562 ms 106080 KB Output is correct
61 Correct 726 ms 105416 KB Output is correct
62 Correct 518 ms 102208 KB Output is correct
63 Correct 4 ms 5016 KB Output is correct
64 Correct 4 ms 5076 KB Output is correct
65 Correct 5 ms 5028 KB Output is correct
66 Correct 5 ms 5140 KB Output is correct
67 Correct 5 ms 5076 KB Output is correct
68 Correct 4 ms 5076 KB Output is correct
69 Correct 4 ms 5076 KB Output is correct
70 Correct 4 ms 5136 KB Output is correct
71 Correct 4 ms 5076 KB Output is correct
72 Correct 4 ms 5136 KB Output is correct
73 Correct 4 ms 5076 KB Output is correct
74 Correct 4 ms 5076 KB Output is correct
75 Correct 4 ms 5076 KB Output is correct
76 Correct 4 ms 5076 KB Output is correct
77 Correct 5 ms 5076 KB Output is correct
78 Correct 4 ms 5004 KB Output is correct
79 Correct 856 ms 107360 KB Output is correct
80 Correct 1113 ms 106600 KB Output is correct
81 Correct 727 ms 110212 KB Output is correct
82 Correct 663 ms 106732 KB Output is correct
83 Correct 469 ms 106616 KB Output is correct
84 Correct 387 ms 106916 KB Output is correct
85 Correct 340 ms 107260 KB Output is correct
86 Correct 663 ms 110148 KB Output is correct
87 Correct 862 ms 111192 KB Output is correct
88 Correct 649 ms 106444 KB Output is correct
89 Correct 677 ms 107116 KB Output is correct
90 Correct 508 ms 107564 KB Output is correct
91 Correct 489 ms 108704 KB Output is correct
92 Correct 4 ms 5076 KB Output is correct
93 Correct 3 ms 5012 KB Output is correct
94 Correct 3 ms 5128 KB Output is correct
95 Correct 3 ms 5136 KB Output is correct
96 Correct 3 ms 5012 KB Output is correct
97 Correct 3 ms 5076 KB Output is correct
98 Correct 670 ms 108504 KB Output is correct
99 Correct 835 ms 106380 KB Output is correct
100 Correct 606 ms 110840 KB Output is correct
101 Correct 591 ms 108236 KB Output is correct
102 Correct 447 ms 108452 KB Output is correct
103 Correct 448 ms 108184 KB Output is correct
104 Correct 338 ms 108600 KB Output is correct
105 Correct 702 ms 113616 KB Output is correct
106 Correct 825 ms 111436 KB Output is correct
107 Correct 618 ms 109236 KB Output is correct
108 Correct 712 ms 107408 KB Output is correct
109 Correct 493 ms 108476 KB Output is correct
110 Correct 504 ms 109008 KB Output is correct
111 Correct 3 ms 5204 KB Output is correct
112 Correct 4 ms 5008 KB Output is correct
113 Correct 4 ms 5076 KB Output is correct
114 Correct 4 ms 5092 KB Output is correct
115 Correct 4 ms 5136 KB Output is correct
116 Correct 638 ms 107436 KB Output is correct
117 Correct 744 ms 108236 KB Output is correct
118 Correct 670 ms 113548 KB Output is correct
119 Correct 615 ms 109608 KB Output is correct
120 Correct 475 ms 109128 KB Output is correct
121 Correct 446 ms 110140 KB Output is correct
122 Correct 364 ms 110404 KB Output is correct
123 Correct 712 ms 113272 KB Output is correct
124 Correct 845 ms 111124 KB Output is correct
125 Correct 665 ms 108176 KB Output is correct
126 Correct 796 ms 108092 KB Output is correct
127 Correct 787 ms 108068 KB Output is correct
128 Correct 665 ms 109036 KB Output is correct
129 Correct 627 ms 109292 KB Output is correct