Submission #569643

# Submission time Handle Problem Language Result Execution time Memory
569643 2022-05-27T15:12:06 Z jamezzz Sprinkler (JOI22_sprinkler) C++17
38 / 100
995 ms 100920 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<=40;++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 4 ms 4948 KB Output is correct
2 Correct 4 ms 5020 KB Output is correct
3 Correct 4 ms 5016 KB Output is correct
4 Incorrect 5 ms 5332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 784 ms 94980 KB Output is correct
3 Correct 511 ms 95640 KB Output is correct
4 Correct 643 ms 98964 KB Output is correct
5 Correct 649 ms 94788 KB Output is correct
6 Correct 497 ms 93152 KB Output is correct
7 Correct 441 ms 95748 KB Output is correct
8 Correct 364 ms 93184 KB Output is correct
9 Correct 995 ms 100864 KB Output is correct
10 Correct 537 ms 100920 KB Output is correct
11 Correct 685 ms 94060 KB Output is correct
12 Correct 440 ms 92576 KB Output is correct
13 Correct 280 ms 95932 KB Output is correct
14 Correct 295 ms 96392 KB Output is correct
15 Correct 329 ms 86204 KB Output is correct
16 Correct 305 ms 94704 KB Output is correct
17 Correct 382 ms 92368 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 4 ms 4948 KB Output is correct
2 Correct 784 ms 94980 KB Output is correct
3 Correct 511 ms 95640 KB Output is correct
4 Correct 643 ms 98964 KB Output is correct
5 Correct 649 ms 94788 KB Output is correct
6 Correct 497 ms 93152 KB Output is correct
7 Correct 441 ms 95748 KB Output is correct
8 Correct 364 ms 93184 KB Output is correct
9 Correct 995 ms 100864 KB Output is correct
10 Correct 537 ms 100920 KB Output is correct
11 Correct 685 ms 94060 KB Output is correct
12 Correct 440 ms 92576 KB Output is correct
13 Correct 280 ms 95932 KB Output is correct
14 Correct 295 ms 96392 KB Output is correct
15 Correct 329 ms 86204 KB Output is correct
16 Correct 305 ms 94704 KB Output is correct
17 Correct 382 ms 92368 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 3 ms 4948 KB Output is correct
24 Correct 599 ms 94884 KB Output is correct
25 Correct 423 ms 95104 KB Output is correct
26 Correct 586 ms 100812 KB Output is correct
27 Correct 554 ms 94592 KB Output is correct
28 Correct 487 ms 95328 KB Output is correct
29 Correct 475 ms 95012 KB Output is correct
30 Correct 309 ms 95272 KB Output is correct
31 Correct 737 ms 98848 KB Output is correct
32 Correct 459 ms 100096 KB Output is correct
33 Correct 735 ms 94748 KB Output is correct
34 Correct 442 ms 94904 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 4 ms 5024 KB Output is correct
37 Correct 4 ms 5024 KB Output is correct
38 Correct 3 ms 5024 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 4 ms 5024 KB Output is correct
42 Correct 4 ms 5076 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 5020 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 4 ms 4952 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5020 KB Output is correct
2 Incorrect 778 ms 97488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 708 ms 97724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 4 ms 5020 KB Output is correct
3 Correct 4 ms 5016 KB Output is correct
4 Incorrect 5 ms 5332 KB Output isn't correct
5 Halted 0 ms 0 KB -