Submission #864499

# Submission time Handle Problem Language Result Execution time Memory
864499 2023-10-23T05:40:36 Z willychan Sprinkler (JOI22_sprinkler) C++14
9 / 100
538 ms 61900 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds

const int N = 2e5+5;
int ans[N];
const int D = 42;
int app[N][D];
vector<int> side[N];
int L = 0;
int p[N];
int n;
void dfs(int cur){
	for(auto i : side[cur]){
		if(!p[i]){
			p[i]=cur;
			dfs(i);
		}
	}
}
void debug(){
	cout<<"\n\n\n";
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<"\n";
	for(int i=1;i<=n;i++){
		for(int j=0;j<(min(D,n+1));j++){
			cout<<app[i][j]<<" ";
		}
		cout<<"\n";
	}
	cout<<"\n\n\n";
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>L;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		side[a].push_back(b);
		side[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		for(int d=0;d<D;d++) app[i][d]=1;
		int a;cin>>a;
		ans[i]=a;
	}
	p[1]=1;
	dfs(1);
	//for(int i=1;i<=n;i++) cout<<p[i]<<" ";
	//cout<<"p\n";
	int Q;cin>>Q;
	while(Q--){
		int t; cin>>t;
		if(t==1){
			int x,d,w;cin>>x>>d>>w;	
			for(int i=0;i<=d;i++){
				ans[x] = (1LL*ans[x]*w)%L;
				if(i!=d) app[x][d-i] = (1LL*app[x][d-i]*w)%L;
				if(x==1) break;
				x = p[x];
			}
			//debug();
		}else{
			int x;cin>>x;
			bool works = 0;
			int rans = ans[x];
			for(int i=0;i<=40;i++){
				if(x==1) works=1;
				//cout<<x<<"t"<<i<<"\n";
				rans = (1LL*rans*app[x][i])%L;
				if(works==1) break;
				x = p[x];
			}
			cout<<rans<<"\n";
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Incorrect 2 ms 6744 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 338 ms 57728 KB Output is correct
3 Correct 264 ms 58152 KB Output is correct
4 Correct 329 ms 60748 KB Output is correct
5 Correct 284 ms 57768 KB Output is correct
6 Correct 218 ms 57492 KB Output is correct
7 Correct 237 ms 58192 KB Output is correct
8 Correct 189 ms 58560 KB Output is correct
9 Correct 515 ms 61800 KB Output is correct
10 Correct 282 ms 61900 KB Output is correct
11 Correct 371 ms 57668 KB Output is correct
12 Correct 257 ms 58040 KB Output is correct
13 Correct 172 ms 58416 KB Output is correct
14 Correct 181 ms 58864 KB Output is correct
15 Correct 179 ms 58468 KB Output is correct
16 Correct 173 ms 58624 KB Output is correct
17 Correct 179 ms 59244 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6644 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 338 ms 57728 KB Output is correct
3 Correct 264 ms 58152 KB Output is correct
4 Correct 329 ms 60748 KB Output is correct
5 Correct 284 ms 57768 KB Output is correct
6 Correct 218 ms 57492 KB Output is correct
7 Correct 237 ms 58192 KB Output is correct
8 Correct 189 ms 58560 KB Output is correct
9 Correct 515 ms 61800 KB Output is correct
10 Correct 282 ms 61900 KB Output is correct
11 Correct 371 ms 57668 KB Output is correct
12 Correct 257 ms 58040 KB Output is correct
13 Correct 172 ms 58416 KB Output is correct
14 Correct 181 ms 58864 KB Output is correct
15 Correct 179 ms 58468 KB Output is correct
16 Correct 173 ms 58624 KB Output is correct
17 Correct 179 ms 59244 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6644 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Incorrect 334 ms 57572 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Incorrect 513 ms 58972 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Incorrect 538 ms 60300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Incorrect 2 ms 6744 KB Output isn't correct
5 Halted 0 ms 0 KB -