Submission #671949

# Submission time Handle Problem Language Result Execution time Memory
671949 2022-12-14T10:03:26 Z Evirir Sprinkler (JOI22_sprinkler) C++17
9 / 100
1331 ms 103628 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
const ll INF = ll(1e18);
int MOD;

ll add(ll a, ll b, ll m = MOD)
{
	a+=b;
	if(abs(a)>=m) a%=m;
	if(a<0) a+=m;
	return a;
}
ll mult(ll a, ll b, ll m = MOD)
{
	if(abs(a)>=m) a%=m;
	if(abs(b)>=m) b%=m;
	a*=b;
	if(abs(a)>=m) a%=m;
	if(a<0) a+=m;
	return a;
}

const bool DEBUG = 0;
const int MAXN = 200005;
const int LG = 21;
const int MAXD = 41;

void dfs(int u, int p, const vector<vector<int>> &adj, vector<int> &prt)
{
	prt[u] = p;
	for (int v : adj[u])
	{
		if (v == p)
			continue;
		dfs(v, u, adj, prt);
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n;
	vector<ll> h;
	vector<vector<int>> adj;
	vector<vector<ll>> depthProd;
	vector<int> prt;

	cin >> n >> MOD;
	adj.resize(n);
	h.resize(n);
	prt.resize(n, -1);
	depthProd.resize(n, vector<ll>(MAXD + 1, 1));
	forn(i,0,n-1)
	{
		int u,v; cin>>u>>v; u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	forn(i, 0, n) cin >> h[i];

	dfs(0, -1, adj, prt);

	int Q;
	cin >> Q;
	while (Q--)
	{
		int t; cin>>t;
		if (t == 1)
		{
			int u, d;
			ll w;
			cin >> u >> d >> w;
			u--;
			for (int i = 0; i <= d; i++)
			{
				depthProd[u][d - i] = mult(depthProd[u][d - i], w);
				u = prt[u];
				if (u == -1)
					break;
			}
		}
		else
		{
			int u;
			cin >> u;
			u--;
			ll prod = h[u];
			for (int i = 0; i <= MAXD; i++)
			{
				if(i == MAXD || i == 0)
				{
					for (int j = i; j <= MAXD; j++)
					prod = mult(prod, depthProd[u][j]);
				}
				else
					prod = mult(prod, depthProd[u][i]);
				
				u = prt[u];
				if (u == -1)
					break;
			}
			cout << prod << '\n';
		}
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 2 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 963 ms 99052 KB Output is correct
3 Correct 453 ms 99808 KB Output is correct
4 Correct 837 ms 102220 KB Output is correct
5 Correct 693 ms 99328 KB Output is correct
6 Correct 437 ms 98900 KB Output is correct
7 Correct 448 ms 99644 KB Output is correct
8 Correct 326 ms 100156 KB Output is correct
9 Correct 1197 ms 103512 KB Output is correct
10 Correct 487 ms 103628 KB Output is correct
11 Correct 937 ms 99068 KB Output is correct
12 Correct 446 ms 99568 KB Output is correct
13 Correct 251 ms 99776 KB Output is correct
14 Correct 269 ms 100308 KB Output is correct
15 Correct 267 ms 99928 KB Output is correct
16 Correct 258 ms 100040 KB Output is correct
17 Correct 276 ms 100556 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 963 ms 99052 KB Output is correct
3 Correct 453 ms 99808 KB Output is correct
4 Correct 837 ms 102220 KB Output is correct
5 Correct 693 ms 99328 KB Output is correct
6 Correct 437 ms 98900 KB Output is correct
7 Correct 448 ms 99644 KB Output is correct
8 Correct 326 ms 100156 KB Output is correct
9 Correct 1197 ms 103512 KB Output is correct
10 Correct 487 ms 103628 KB Output is correct
11 Correct 937 ms 99068 KB Output is correct
12 Correct 446 ms 99568 KB Output is correct
13 Correct 251 ms 99776 KB Output is correct
14 Correct 269 ms 100308 KB Output is correct
15 Correct 267 ms 99928 KB Output is correct
16 Correct 258 ms 100040 KB Output is correct
17 Correct 276 ms 100556 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Incorrect 955 ms 99064 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1331 ms 100868 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1316 ms 101760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 2 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -