#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<ll, ll>
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i<b; ++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 2e5+5;
signed L;
vector<int> rawt[maxn], g[maxn];
int par[maxn];
ll H[maxn];
int ordpos[maxn], dep[maxn];;
vector<int> depv[maxn];
ll seg[maxn*4], tg[maxn*4];
inline void push(int o, int l, int r) {
if (tg[o] != 1) {
seg[o] *= tg[o]; seg[o] %= L;
if (l!=r) {
tg[o*2] = tg[o*2] * tg[o] % L;
tg[o*2+1] = tg[o*2+1] * tg[o] % L;
}
tg[o] = 1;
}
}
void MO(int L, int R, int v, int o=1, int l=0, int r=maxn-1) {
push(o,l,r);
if (l > R || r < L) return;
if (l >= L && r <= R) {
tg[o] = tg[o] * v % ::L;
push(o,l,r); return;
}
int mid = (l+r)/2;
MO(L,R,v,o*2,l,mid); MO(L,R,v,o*2+1,mid+1,r);
seg[o] = seg[o*2] * seg[o*2+1] % ::L;
}
ll get(int p, int o=1, int l=0, int r=maxn-1) {
if (l > p || r < p) assert(0);
push(o,l,r);
if (l == r) return seg[o];
int mid = (l+r)/2;
if (p <= mid) return get(p,o*2,l,mid);
else return get(p,o*2+1,mid+1,r);
}
void build(){
fill(seg, seg+maxn*4, 1);
fill(tg, tg+maxn*4, 1);
}
void dfs1(int v, int p) {
par[v] = p;
depv[dep[v]].pb(v);
for (int u : rawt[v]) {
if (u == p) continue;
g[v].pb(u);
dep[u] = dep[v] + 1;
dfs1(u,v);
}
}
pii rnghere[maxn][41];
void dfs2(int v) {
fill(rnghere[v], rnghere[v]+41, pii{10000000,-1});
rnghere[v][0] = {ordpos[v],ordpos[v]};
for (int u : g[v]) {
dfs2(u);
REP(d, 40) {
if (rnghere[u][d].s != -1) {
MN(rnghere[v][d+1].f, rnghere[u][d].f);
MX(rnghere[v][d+1].s, rnghere[u][d].s);
}
}
}
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
int n; cin>>n>>L;
REP(i,n-1) {
int a,b; cin>>a>>b; --a; --b;
rawt[a].pb(b);
rawt[b].pb(a);
}
dfs1(0,-1);
int IT = 0;
REP(i, maxn) {
for (int e : depv[i]) {
bug(e, IT);
ordpos[e] = IT++;
}
}
build();
dfs2(0);
REP(i,n) cin>>H[i], MO(ordpos[i],ordpos[i],H[i]);
int q; cin>>q;
while (q--) {
int tp; cin>>tp;
if (tp == 1) {
int v, d, w; cin>>v>>d>>w; --v;
int at = v;
for (int dp = dep[v] + d; dp >= dep[v] - d; dp--) {
if (dp < 0 || dp >= maxn || SZ(depv[dp]) == 0) continue;
while (at != 0 && dep[v] - dep[par[at]] + dp - dep[par[at]] <= d) {
at = par[at];
}
pii ha = rnghere[at][dp-dep[at]];
if (ha.f == -1) continue;
bug(ha.f, ha.s, w);
MO(ha.f, ha.s, w);
}
}else{
int v; cin>>v; --v;
bug(ordpos[v]);
cout<<get(ordpos[v])<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
26964 KB |
Output is correct |
2 |
Correct |
14 ms |
26964 KB |
Output is correct |
3 |
Correct |
14 ms |
26964 KB |
Output is correct |
4 |
Correct |
22 ms |
27744 KB |
Output is correct |
5 |
Correct |
21 ms |
27752 KB |
Output is correct |
6 |
Correct |
19 ms |
27744 KB |
Output is correct |
7 |
Correct |
18 ms |
27732 KB |
Output is correct |
8 |
Correct |
16 ms |
27732 KB |
Output is correct |
9 |
Correct |
14 ms |
26964 KB |
Output is correct |
10 |
Correct |
14 ms |
26984 KB |
Output is correct |
11 |
Correct |
14 ms |
26984 KB |
Output is correct |
12 |
Correct |
13 ms |
27000 KB |
Output is correct |
13 |
Correct |
13 ms |
26980 KB |
Output is correct |
14 |
Correct |
15 ms |
26992 KB |
Output is correct |
15 |
Correct |
14 ms |
26888 KB |
Output is correct |
16 |
Correct |
14 ms |
26996 KB |
Output is correct |
17 |
Correct |
14 ms |
26996 KB |
Output is correct |
18 |
Correct |
15 ms |
26988 KB |
Output is correct |
19 |
Correct |
14 ms |
26980 KB |
Output is correct |
20 |
Correct |
15 ms |
26892 KB |
Output is correct |
21 |
Correct |
16 ms |
26976 KB |
Output is correct |
22 |
Correct |
14 ms |
26964 KB |
Output is correct |
23 |
Correct |
13 ms |
26984 KB |
Output is correct |
24 |
Correct |
13 ms |
26936 KB |
Output is correct |
25 |
Correct |
13 ms |
26980 KB |
Output is correct |
26 |
Correct |
13 ms |
26984 KB |
Output is correct |
27 |
Correct |
13 ms |
26884 KB |
Output is correct |
28 |
Correct |
14 ms |
26964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
26964 KB |
Output is correct |
2 |
Correct |
659 ms |
181596 KB |
Output is correct |
3 |
Correct |
1020 ms |
178488 KB |
Output is correct |
4 |
Correct |
881 ms |
192868 KB |
Output is correct |
5 |
Correct |
788 ms |
180000 KB |
Output is correct |
6 |
Correct |
755 ms |
178884 KB |
Output is correct |
7 |
Correct |
809 ms |
178932 KB |
Output is correct |
8 |
Correct |
651 ms |
179000 KB |
Output is correct |
9 |
Correct |
749 ms |
201596 KB |
Output is correct |
10 |
Correct |
1118 ms |
196600 KB |
Output is correct |
11 |
Correct |
627 ms |
181656 KB |
Output is correct |
12 |
Correct |
1060 ms |
178480 KB |
Output is correct |
13 |
Correct |
1057 ms |
178176 KB |
Output is correct |
14 |
Correct |
1037 ms |
176736 KB |
Output is correct |
15 |
Correct |
992 ms |
176476 KB |
Output is correct |
16 |
Correct |
948 ms |
176244 KB |
Output is correct |
17 |
Correct |
1097 ms |
177116 KB |
Output is correct |
18 |
Correct |
14 ms |
26964 KB |
Output is correct |
19 |
Correct |
14 ms |
26964 KB |
Output is correct |
20 |
Correct |
14 ms |
26964 KB |
Output is correct |
21 |
Correct |
14 ms |
26984 KB |
Output is correct |
22 |
Correct |
14 ms |
27000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
26964 KB |
Output is correct |
2 |
Correct |
659 ms |
181596 KB |
Output is correct |
3 |
Correct |
1020 ms |
178488 KB |
Output is correct |
4 |
Correct |
881 ms |
192868 KB |
Output is correct |
5 |
Correct |
788 ms |
180000 KB |
Output is correct |
6 |
Correct |
755 ms |
178884 KB |
Output is correct |
7 |
Correct |
809 ms |
178932 KB |
Output is correct |
8 |
Correct |
651 ms |
179000 KB |
Output is correct |
9 |
Correct |
749 ms |
201596 KB |
Output is correct |
10 |
Correct |
1118 ms |
196600 KB |
Output is correct |
11 |
Correct |
627 ms |
181656 KB |
Output is correct |
12 |
Correct |
1060 ms |
178480 KB |
Output is correct |
13 |
Correct |
1057 ms |
178176 KB |
Output is correct |
14 |
Correct |
1037 ms |
176736 KB |
Output is correct |
15 |
Correct |
992 ms |
176476 KB |
Output is correct |
16 |
Correct |
948 ms |
176244 KB |
Output is correct |
17 |
Correct |
1097 ms |
177116 KB |
Output is correct |
18 |
Correct |
14 ms |
26964 KB |
Output is correct |
19 |
Correct |
14 ms |
26964 KB |
Output is correct |
20 |
Correct |
14 ms |
26964 KB |
Output is correct |
21 |
Correct |
14 ms |
26984 KB |
Output is correct |
22 |
Correct |
14 ms |
27000 KB |
Output is correct |
23 |
Correct |
13 ms |
26964 KB |
Output is correct |
24 |
Correct |
694 ms |
184924 KB |
Output is correct |
25 |
Correct |
1241 ms |
187904 KB |
Output is correct |
26 |
Correct |
949 ms |
206388 KB |
Output is correct |
27 |
Correct |
893 ms |
187468 KB |
Output is correct |
28 |
Correct |
812 ms |
186344 KB |
Output is correct |
29 |
Correct |
799 ms |
185936 KB |
Output is correct |
30 |
Correct |
782 ms |
186512 KB |
Output is correct |
31 |
Correct |
742 ms |
200584 KB |
Output is correct |
32 |
Correct |
1341 ms |
205804 KB |
Output is correct |
33 |
Correct |
717 ms |
187252 KB |
Output is correct |
34 |
Correct |
1377 ms |
187704 KB |
Output is correct |
35 |
Correct |
13 ms |
26968 KB |
Output is correct |
36 |
Correct |
16 ms |
26964 KB |
Output is correct |
37 |
Correct |
14 ms |
26972 KB |
Output is correct |
38 |
Correct |
14 ms |
27000 KB |
Output is correct |
39 |
Correct |
15 ms |
26944 KB |
Output is correct |
40 |
Correct |
15 ms |
26964 KB |
Output is correct |
41 |
Correct |
14 ms |
26964 KB |
Output is correct |
42 |
Correct |
15 ms |
26984 KB |
Output is correct |
43 |
Correct |
13 ms |
26932 KB |
Output is correct |
44 |
Correct |
13 ms |
27076 KB |
Output is correct |
45 |
Correct |
13 ms |
26964 KB |
Output is correct |
46 |
Correct |
18 ms |
26976 KB |
Output is correct |
47 |
Correct |
14 ms |
26964 KB |
Output is correct |
48 |
Correct |
14 ms |
26984 KB |
Output is correct |
49 |
Correct |
14 ms |
26976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
26964 KB |
Output is correct |
2 |
Correct |
1666 ms |
198432 KB |
Output is correct |
3 |
Execution timed out |
4083 ms |
193016 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
26964 KB |
Output is correct |
2 |
Correct |
1734 ms |
194084 KB |
Output is correct |
3 |
Execution timed out |
4067 ms |
188264 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
26964 KB |
Output is correct |
2 |
Correct |
14 ms |
26964 KB |
Output is correct |
3 |
Correct |
14 ms |
26964 KB |
Output is correct |
4 |
Correct |
22 ms |
27744 KB |
Output is correct |
5 |
Correct |
21 ms |
27752 KB |
Output is correct |
6 |
Correct |
19 ms |
27744 KB |
Output is correct |
7 |
Correct |
18 ms |
27732 KB |
Output is correct |
8 |
Correct |
16 ms |
27732 KB |
Output is correct |
9 |
Correct |
14 ms |
26964 KB |
Output is correct |
10 |
Correct |
14 ms |
26984 KB |
Output is correct |
11 |
Correct |
14 ms |
26984 KB |
Output is correct |
12 |
Correct |
13 ms |
27000 KB |
Output is correct |
13 |
Correct |
13 ms |
26980 KB |
Output is correct |
14 |
Correct |
15 ms |
26992 KB |
Output is correct |
15 |
Correct |
14 ms |
26888 KB |
Output is correct |
16 |
Correct |
14 ms |
26996 KB |
Output is correct |
17 |
Correct |
14 ms |
26996 KB |
Output is correct |
18 |
Correct |
15 ms |
26988 KB |
Output is correct |
19 |
Correct |
14 ms |
26980 KB |
Output is correct |
20 |
Correct |
15 ms |
26892 KB |
Output is correct |
21 |
Correct |
16 ms |
26976 KB |
Output is correct |
22 |
Correct |
14 ms |
26964 KB |
Output is correct |
23 |
Correct |
13 ms |
26984 KB |
Output is correct |
24 |
Correct |
13 ms |
26936 KB |
Output is correct |
25 |
Correct |
13 ms |
26980 KB |
Output is correct |
26 |
Correct |
13 ms |
26984 KB |
Output is correct |
27 |
Correct |
13 ms |
26884 KB |
Output is correct |
28 |
Correct |
14 ms |
26964 KB |
Output is correct |
29 |
Correct |
13 ms |
26964 KB |
Output is correct |
30 |
Correct |
659 ms |
181596 KB |
Output is correct |
31 |
Correct |
1020 ms |
178488 KB |
Output is correct |
32 |
Correct |
881 ms |
192868 KB |
Output is correct |
33 |
Correct |
788 ms |
180000 KB |
Output is correct |
34 |
Correct |
755 ms |
178884 KB |
Output is correct |
35 |
Correct |
809 ms |
178932 KB |
Output is correct |
36 |
Correct |
651 ms |
179000 KB |
Output is correct |
37 |
Correct |
749 ms |
201596 KB |
Output is correct |
38 |
Correct |
1118 ms |
196600 KB |
Output is correct |
39 |
Correct |
627 ms |
181656 KB |
Output is correct |
40 |
Correct |
1060 ms |
178480 KB |
Output is correct |
41 |
Correct |
1057 ms |
178176 KB |
Output is correct |
42 |
Correct |
1037 ms |
176736 KB |
Output is correct |
43 |
Correct |
992 ms |
176476 KB |
Output is correct |
44 |
Correct |
948 ms |
176244 KB |
Output is correct |
45 |
Correct |
1097 ms |
177116 KB |
Output is correct |
46 |
Correct |
14 ms |
26964 KB |
Output is correct |
47 |
Correct |
14 ms |
26964 KB |
Output is correct |
48 |
Correct |
14 ms |
26964 KB |
Output is correct |
49 |
Correct |
14 ms |
26984 KB |
Output is correct |
50 |
Correct |
14 ms |
27000 KB |
Output is correct |
51 |
Correct |
13 ms |
26964 KB |
Output is correct |
52 |
Correct |
694 ms |
184924 KB |
Output is correct |
53 |
Correct |
1241 ms |
187904 KB |
Output is correct |
54 |
Correct |
949 ms |
206388 KB |
Output is correct |
55 |
Correct |
893 ms |
187468 KB |
Output is correct |
56 |
Correct |
812 ms |
186344 KB |
Output is correct |
57 |
Correct |
799 ms |
185936 KB |
Output is correct |
58 |
Correct |
782 ms |
186512 KB |
Output is correct |
59 |
Correct |
742 ms |
200584 KB |
Output is correct |
60 |
Correct |
1341 ms |
205804 KB |
Output is correct |
61 |
Correct |
717 ms |
187252 KB |
Output is correct |
62 |
Correct |
1377 ms |
187704 KB |
Output is correct |
63 |
Correct |
13 ms |
26968 KB |
Output is correct |
64 |
Correct |
16 ms |
26964 KB |
Output is correct |
65 |
Correct |
14 ms |
26972 KB |
Output is correct |
66 |
Correct |
14 ms |
27000 KB |
Output is correct |
67 |
Correct |
15 ms |
26944 KB |
Output is correct |
68 |
Correct |
15 ms |
26964 KB |
Output is correct |
69 |
Correct |
14 ms |
26964 KB |
Output is correct |
70 |
Correct |
15 ms |
26984 KB |
Output is correct |
71 |
Correct |
13 ms |
26932 KB |
Output is correct |
72 |
Correct |
13 ms |
27076 KB |
Output is correct |
73 |
Correct |
13 ms |
26964 KB |
Output is correct |
74 |
Correct |
18 ms |
26976 KB |
Output is correct |
75 |
Correct |
14 ms |
26964 KB |
Output is correct |
76 |
Correct |
14 ms |
26984 KB |
Output is correct |
77 |
Correct |
14 ms |
26976 KB |
Output is correct |
78 |
Correct |
13 ms |
26964 KB |
Output is correct |
79 |
Correct |
1666 ms |
198432 KB |
Output is correct |
80 |
Execution timed out |
4083 ms |
193016 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |