Submission #569657

# Submission time Handle Problem Language Result Execution time Memory
569657 2022-05-27T15:19:55 Z jamezzz Sprinkler (JOI22_sprinkler) C++17
100 / 100
1063 ms 100044 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 200005

int n,l,q,h[maxn],par[maxn];
ll mult[maxn][45]; //mult[i][j]: at node i, this thing can travel j more
vi AL[maxn];

void dfs(int u){
	for(int v:AL[u]){
		if(v==par[u])continue;
		par[v]=u;
		dfs(v);
	}
}

int main(){
	sf("%d%d",&n,&l);
	for(int i=0;i<n-1;++i){
		int a,b;sf("%d%d",&a,&b);
		AL[a].pb(b);
		AL[b].pb(a);
	}
	for(int i=1;i<=n;++i){
		sf("%d",&h[i]);
	}
	dfs(1);
	
	for(int i=0;i<=n;++i){
		for(int j=0;j<=41;++j){
			mult[i][j]=1;
		}
	}
	
	sf("%d",&q);
	while(q--){
		int t;sf("%d",&t);
		if(t==1){
			int x,d,w;sf("%d%d%d",&x,&d,&w);
			int cur=x;
			for(int i=d;i>=0;--i){
				mult[cur][i]*=w;
				mult[cur][i]%=l;
				if(par[cur]==0){
					for(int j=i-1;j>=0;--j){
						mult[cur][j]*=w;
						mult[cur][j]%=l;
					}
					break;
				}
				else cur=par[cur];
			}
			
			/*
			for(int i=1;i<=4;++i){
				pf("mult[%d]: ",i);
				for(int j=0;j<=4;++j){
					pf("%lld ",mult[i][j]);
				}
				pf("\n");
			}
			*/
		}
		else{
			int x;sf("%d",&x);
			ll ans=h[x];
			int cur=x,d=0;
			while(d<=40&&cur!=0){
				ans*=mult[cur][d];
				ans%=l;
				if(par[cur]!=0){
					ans*=mult[cur][d+1];
					ans%=l;
				}
				cur=par[cur];
				++d;
			}
			pf("%lld\n",ans);
		}
	}
}

/*
4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
*/

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:61:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  sf("%d%d",&n,&l);
      |    ^
sprinkler.cpp:63:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   int a,b;sf("%d%d",&a,&b);
      |             ^
sprinkler.cpp:68:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |   sf("%d",&h[i]);
      |     ^
sprinkler.cpp:78:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |  sf("%d",&q);
      |    ^
sprinkler.cpp:80:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   int t;sf("%d",&t);
      |           ^
sprinkler.cpp:82:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |    int x,d,w;sf("%d%d%d",&x,&d,&w);
      |                ^
sprinkler.cpp:108:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |    int x;sf("%d",&x);
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5352 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5020 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5016 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5028 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 581 ms 86812 KB Output is correct
3 Correct 382 ms 83624 KB Output is correct
4 Correct 530 ms 89168 KB Output is correct
5 Correct 491 ms 85248 KB Output is correct
6 Correct 396 ms 85276 KB Output is correct
7 Correct 406 ms 85616 KB Output is correct
8 Correct 313 ms 85928 KB Output is correct
9 Correct 733 ms 92728 KB Output is correct
10 Correct 395 ms 89132 KB Output is correct
11 Correct 613 ms 86824 KB Output is correct
12 Correct 394 ms 83740 KB Output is correct
13 Correct 271 ms 84340 KB Output is correct
14 Correct 270 ms 84372 KB Output is correct
15 Correct 285 ms 84296 KB Output is correct
16 Correct 297 ms 84312 KB Output is correct
17 Correct 273 ms 84808 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 581 ms 86812 KB Output is correct
3 Correct 382 ms 83624 KB Output is correct
4 Correct 530 ms 89168 KB Output is correct
5 Correct 491 ms 85248 KB Output is correct
6 Correct 396 ms 85276 KB Output is correct
7 Correct 406 ms 85616 KB Output is correct
8 Correct 313 ms 85928 KB Output is correct
9 Correct 733 ms 92728 KB Output is correct
10 Correct 395 ms 89132 KB Output is correct
11 Correct 613 ms 86824 KB Output is correct
12 Correct 394 ms 83740 KB Output is correct
13 Correct 271 ms 84340 KB Output is correct
14 Correct 270 ms 84372 KB Output is correct
15 Correct 285 ms 84296 KB Output is correct
16 Correct 297 ms 84312 KB Output is correct
17 Correct 273 ms 84808 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 651 ms 86984 KB Output is correct
25 Correct 384 ms 83736 KB Output is correct
26 Correct 538 ms 91048 KB Output is correct
27 Correct 489 ms 85288 KB Output is correct
28 Correct 396 ms 85360 KB Output is correct
29 Correct 449 ms 85416 KB Output is correct
30 Correct 331 ms 86124 KB Output is correct
31 Correct 731 ms 90996 KB Output is correct
32 Correct 436 ms 89360 KB Output is correct
33 Correct 571 ms 86968 KB Output is correct
34 Correct 391 ms 83656 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4972 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 5032 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 774 ms 90156 KB Output is correct
3 Correct 732 ms 96356 KB Output is correct
4 Correct 687 ms 96380 KB Output is correct
5 Correct 620 ms 91924 KB Output is correct
6 Correct 447 ms 91688 KB Output is correct
7 Correct 404 ms 92084 KB Output is correct
8 Correct 341 ms 92432 KB Output is correct
9 Correct 747 ms 95984 KB Output is correct
10 Correct 768 ms 97400 KB Output is correct
11 Correct 675 ms 91584 KB Output is correct
12 Correct 669 ms 92140 KB Output is correct
13 Correct 471 ms 92780 KB Output is correct
14 Correct 493 ms 93852 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 830 ms 90808 KB Output is correct
3 Correct 701 ms 95744 KB Output is correct
4 Correct 801 ms 96824 KB Output is correct
5 Correct 665 ms 93372 KB Output is correct
6 Correct 501 ms 93432 KB Output is correct
7 Correct 500 ms 93312 KB Output is correct
8 Correct 367 ms 93744 KB Output is correct
9 Correct 1063 ms 99948 KB Output is correct
10 Correct 821 ms 97888 KB Output is correct
11 Correct 847 ms 94168 KB Output is correct
12 Correct 879 ms 92548 KB Output is correct
13 Correct 470 ms 93604 KB Output is correct
14 Correct 541 ms 94004 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 5020 KB Output is correct
17 Correct 4 ms 5020 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5352 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5460 KB Output is correct
9 Correct 4 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5024 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5020 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5016 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5028 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 581 ms 86812 KB Output is correct
31 Correct 382 ms 83624 KB Output is correct
32 Correct 530 ms 89168 KB Output is correct
33 Correct 491 ms 85248 KB Output is correct
34 Correct 396 ms 85276 KB Output is correct
35 Correct 406 ms 85616 KB Output is correct
36 Correct 313 ms 85928 KB Output is correct
37 Correct 733 ms 92728 KB Output is correct
38 Correct 395 ms 89132 KB Output is correct
39 Correct 613 ms 86824 KB Output is correct
40 Correct 394 ms 83740 KB Output is correct
41 Correct 271 ms 84340 KB Output is correct
42 Correct 270 ms 84372 KB Output is correct
43 Correct 285 ms 84296 KB Output is correct
44 Correct 297 ms 84312 KB Output is correct
45 Correct 273 ms 84808 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 651 ms 86984 KB Output is correct
53 Correct 384 ms 83736 KB Output is correct
54 Correct 538 ms 91048 KB Output is correct
55 Correct 489 ms 85288 KB Output is correct
56 Correct 396 ms 85360 KB Output is correct
57 Correct 449 ms 85416 KB Output is correct
58 Correct 331 ms 86124 KB Output is correct
59 Correct 731 ms 90996 KB Output is correct
60 Correct 436 ms 89360 KB Output is correct
61 Correct 571 ms 86968 KB Output is correct
62 Correct 391 ms 83656 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4972 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 5032 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 774 ms 90156 KB Output is correct
80 Correct 732 ms 96356 KB Output is correct
81 Correct 687 ms 96380 KB Output is correct
82 Correct 620 ms 91924 KB Output is correct
83 Correct 447 ms 91688 KB Output is correct
84 Correct 404 ms 92084 KB Output is correct
85 Correct 341 ms 92432 KB Output is correct
86 Correct 747 ms 95984 KB Output is correct
87 Correct 768 ms 97400 KB Output is correct
88 Correct 675 ms 91584 KB Output is correct
89 Correct 669 ms 92140 KB Output is correct
90 Correct 471 ms 92780 KB Output is correct
91 Correct 493 ms 93852 KB Output is correct
92 Correct 4 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 5016 KB Output is correct
95 Correct 3 ms 4952 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 830 ms 90808 KB Output is correct
99 Correct 701 ms 95744 KB Output is correct
100 Correct 801 ms 96824 KB Output is correct
101 Correct 665 ms 93372 KB Output is correct
102 Correct 501 ms 93432 KB Output is correct
103 Correct 500 ms 93312 KB Output is correct
104 Correct 367 ms 93744 KB Output is correct
105 Correct 1063 ms 99948 KB Output is correct
106 Correct 821 ms 97888 KB Output is correct
107 Correct 847 ms 94168 KB Output is correct
108 Correct 879 ms 92548 KB Output is correct
109 Correct 470 ms 93604 KB Output is correct
110 Correct 541 ms 94004 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 4 ms 5020 KB Output is correct
113 Correct 4 ms 5020 KB Output is correct
114 Correct 3 ms 4948 KB Output is correct
115 Correct 4 ms 4948 KB Output is correct
116 Correct 729 ms 92580 KB Output is correct
117 Correct 849 ms 95344 KB Output is correct
118 Correct 807 ms 100044 KB Output is correct
119 Correct 642 ms 94692 KB Output is correct
120 Correct 486 ms 94244 KB Output is correct
121 Correct 515 ms 95116 KB Output is correct
122 Correct 363 ms 95328 KB Output is correct
123 Correct 817 ms 99644 KB Output is correct
124 Correct 755 ms 98736 KB Output is correct
125 Correct 688 ms 93304 KB Output is correct
126 Correct 683 ms 95104 KB Output is correct
127 Correct 776 ms 95472 KB Output is correct
128 Correct 494 ms 95376 KB Output is correct
129 Correct 510 ms 96872 KB Output is correct