Submission #892666

# Submission time Handle Problem Language Result Execution time Memory
892666 2023-12-25T16:36:58 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
0 / 100
750 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;/*
<<<<It's never too late for a new beginning in your life>>>>
Today is hard
  tomorrow will worse
  but the day after tomorrow will be the sunshine..
 
HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............
Never give up  */
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///*                                                                                                                          */
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vii;
const long long N = 2e5+50, inf = 1e18, mod = 1e9+7;
vi g[N];
int pre[N];
void dfs(int i, int pr){
	pre[i] = pr;
	for(auto to:g[i])if(to!=pr)dfs(to, i);
}
void solve(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0, -1);
	int dp[n][41];
	for(auto &i:dp){
		for(auto &j:i)j = 1;
	}
	for(int i = 0; i < n; i++)cin >> dp[i][0];
	int q;
	cin >> q;
	while(q--){
		int type, x;
		cin >> type >> x;
		x--;
		if(type == 1){
			int d, c;
			cin >> d >> c;
			while(1){
				dp[x][d] = dp[x][d] * c % m;
				if(d-- == 0) break;
				dp[x][d] = dp[x][d] * c % m;
				if(x) x = pre[x];
				else if(d-- == 0) break;
			}
		}
		else{
			int ans = 1;
			for(int d = 0; d <= 40 && x >= 0; d++, x = pre[x]){
				ans = ans * dp[x][d] % m;
			}
			cout << ans << '\n';
        }
	}
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	//~ cin >> t;
	while(t--){
		solve();
	}
}



Compilation message

sprinkler.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 12892 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 12892 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 750 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -