답안 #671953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671953 2022-12-14T10:22:11 Z Evirir Sprinkler (JOI22_sprinkler) C++17
100 / 100
1549 ms 103692 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);
ll 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 || u == 0)
				{
					for (int j = i; j <= MAXD; j++)
						prod = mult(prod, depthProd[u][j]);
				}
				else
				{
					prod = mult(prod, depthProd[u][i]);
					if (i + 1 <= MAXD)
					{
						prod = mult(prod, depthProd[u][i + 1]);
					}
				}

				u = prt[u];
				if (u == -1)
					break;
			}
			cout << prod << '\n';
		}
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1012 ms 90848 KB Output is correct
3 Correct 432 ms 87652 KB Output is correct
4 Correct 916 ms 92180 KB Output is correct
5 Correct 729 ms 89292 KB Output is correct
6 Correct 414 ms 89328 KB Output is correct
7 Correct 382 ms 89508 KB Output is correct
8 Correct 308 ms 89936 KB Output is correct
9 Correct 1393 ms 95468 KB Output is correct
10 Correct 469 ms 91832 KB Output is correct
11 Correct 973 ms 90792 KB Output is correct
12 Correct 455 ms 87592 KB Output is correct
13 Correct 246 ms 88256 KB Output is correct
14 Correct 252 ms 88548 KB Output is correct
15 Correct 252 ms 88240 KB Output is correct
16 Correct 255 ms 88096 KB Output is correct
17 Correct 274 ms 88516 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1012 ms 90848 KB Output is correct
3 Correct 432 ms 87652 KB Output is correct
4 Correct 916 ms 92180 KB Output is correct
5 Correct 729 ms 89292 KB Output is correct
6 Correct 414 ms 89328 KB Output is correct
7 Correct 382 ms 89508 KB Output is correct
8 Correct 308 ms 89936 KB Output is correct
9 Correct 1393 ms 95468 KB Output is correct
10 Correct 469 ms 91832 KB Output is correct
11 Correct 973 ms 90792 KB Output is correct
12 Correct 455 ms 87592 KB Output is correct
13 Correct 246 ms 88256 KB Output is correct
14 Correct 252 ms 88548 KB Output is correct
15 Correct 252 ms 88240 KB Output is correct
16 Correct 255 ms 88096 KB Output is correct
17 Correct 274 ms 88516 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 998 ms 90892 KB Output is correct
25 Correct 466 ms 99724 KB Output is correct
26 Correct 1101 ms 103680 KB Output is correct
27 Correct 792 ms 99360 KB Output is correct
28 Correct 446 ms 99508 KB Output is correct
29 Correct 403 ms 99044 KB Output is correct
30 Correct 320 ms 100084 KB Output is correct
31 Correct 1401 ms 102424 KB Output is correct
32 Correct 506 ms 103692 KB Output is correct
33 Correct 1024 ms 99088 KB Output is correct
34 Correct 448 ms 99500 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1442 ms 92764 KB Output is correct
3 Correct 1200 ms 100256 KB Output is correct
4 Correct 1211 ms 99872 KB Output is correct
5 Correct 847 ms 96440 KB Output is correct
6 Correct 445 ms 96460 KB Output is correct
7 Correct 407 ms 96608 KB Output is correct
8 Correct 304 ms 97088 KB Output is correct
9 Correct 1473 ms 99284 KB Output is correct
10 Correct 1183 ms 100856 KB Output is correct
11 Correct 1035 ms 95976 KB Output is correct
12 Correct 859 ms 96796 KB Output is correct
13 Correct 492 ms 97780 KB Output is correct
14 Correct 533 ms 98160 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1460 ms 93872 KB Output is correct
3 Correct 1378 ms 99528 KB Output is correct
4 Correct 1131 ms 100540 KB Output is correct
5 Correct 933 ms 97996 KB Output is correct
6 Correct 515 ms 97996 KB Output is correct
7 Correct 473 ms 97816 KB Output is correct
8 Correct 397 ms 98164 KB Output is correct
9 Correct 1534 ms 102972 KB Output is correct
10 Correct 1254 ms 101532 KB Output is correct
11 Correct 1240 ms 98828 KB Output is correct
12 Correct 907 ms 97100 KB Output is correct
13 Correct 554 ms 97940 KB Output is correct
14 Correct 597 ms 98628 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1012 ms 90848 KB Output is correct
31 Correct 432 ms 87652 KB Output is correct
32 Correct 916 ms 92180 KB Output is correct
33 Correct 729 ms 89292 KB Output is correct
34 Correct 414 ms 89328 KB Output is correct
35 Correct 382 ms 89508 KB Output is correct
36 Correct 308 ms 89936 KB Output is correct
37 Correct 1393 ms 95468 KB Output is correct
38 Correct 469 ms 91832 KB Output is correct
39 Correct 973 ms 90792 KB Output is correct
40 Correct 455 ms 87592 KB Output is correct
41 Correct 246 ms 88256 KB Output is correct
42 Correct 252 ms 88548 KB Output is correct
43 Correct 252 ms 88240 KB Output is correct
44 Correct 255 ms 88096 KB Output is correct
45 Correct 274 ms 88516 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 998 ms 90892 KB Output is correct
53 Correct 466 ms 99724 KB Output is correct
54 Correct 1101 ms 103680 KB Output is correct
55 Correct 792 ms 99360 KB Output is correct
56 Correct 446 ms 99508 KB Output is correct
57 Correct 403 ms 99044 KB Output is correct
58 Correct 320 ms 100084 KB Output is correct
59 Correct 1401 ms 102424 KB Output is correct
60 Correct 506 ms 103692 KB Output is correct
61 Correct 1024 ms 99088 KB Output is correct
62 Correct 448 ms 99500 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 320 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1442 ms 92764 KB Output is correct
80 Correct 1200 ms 100256 KB Output is correct
81 Correct 1211 ms 99872 KB Output is correct
82 Correct 847 ms 96440 KB Output is correct
83 Correct 445 ms 96460 KB Output is correct
84 Correct 407 ms 96608 KB Output is correct
85 Correct 304 ms 97088 KB Output is correct
86 Correct 1473 ms 99284 KB Output is correct
87 Correct 1183 ms 100856 KB Output is correct
88 Correct 1035 ms 95976 KB Output is correct
89 Correct 859 ms 96796 KB Output is correct
90 Correct 492 ms 97780 KB Output is correct
91 Correct 533 ms 98160 KB Output is correct
92 Correct 1 ms 212 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 324 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 1460 ms 93872 KB Output is correct
99 Correct 1378 ms 99528 KB Output is correct
100 Correct 1131 ms 100540 KB Output is correct
101 Correct 933 ms 97996 KB Output is correct
102 Correct 515 ms 97996 KB Output is correct
103 Correct 473 ms 97816 KB Output is correct
104 Correct 397 ms 98164 KB Output is correct
105 Correct 1534 ms 102972 KB Output is correct
106 Correct 1254 ms 101532 KB Output is correct
107 Correct 1240 ms 98828 KB Output is correct
108 Correct 907 ms 97100 KB Output is correct
109 Correct 554 ms 97940 KB Output is correct
110 Correct 597 ms 98628 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 1 ms 324 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 1 ms 324 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 1174 ms 96992 KB Output is correct
117 Correct 966 ms 99908 KB Output is correct
118 Correct 1275 ms 103668 KB Output is correct
119 Correct 1079 ms 99424 KB Output is correct
120 Correct 534 ms 98984 KB Output is correct
121 Correct 527 ms 99932 KB Output is correct
122 Correct 383 ms 100032 KB Output is correct
123 Correct 1549 ms 102748 KB Output is correct
124 Correct 1343 ms 102256 KB Output is correct
125 Correct 1279 ms 98288 KB Output is correct
126 Correct 1010 ms 99636 KB Output is correct
127 Correct 978 ms 100068 KB Output is correct
128 Correct 609 ms 100824 KB Output is correct
129 Correct 629 ms 101204 KB Output is correct