#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxq = 4e5 + 10;
struct query
{
int type, ver, d, t;
ll w;
}ask[maxq];
const int maxn = 2e5 + 10;
int n, q;
ll l, h[maxn];
vector < query > task[maxn];
vector < int > adj[maxn];
bool cmp(query a1, query a2)
{
return a1.d < a2.d;
}
void input()
{
cin >> n >> l;
for (int i = 1; i < n; i ++)
{
int v, u;
cin >> v >> u;
adj[v].push_back(u);
adj[u].push_back(v);
}
for (int i = 1; i <= n; i ++)
cin >> h[i];
cin >> q;
for (int i = 1; i <= q; i ++)
{
cin >> ask[i].type;
if (ask[i].type == 1)
cin >> ask[i].ver >> ask[i].d >> ask[i].w;
else
cin >> ask[i].ver;
ask[i].t = i;
}
}
void offline_queries()
{
for (int i = 1; i <= q; i ++)
{
if (ask[i].type == 1)
task[ask[i].ver].push_back(ask[i]);
}
for (int i = 1; i <= n; i ++)
sort(task[i].begin(), task[i].end(), cmp);
}
int par[maxn];
void dfs(int v)
{
for (int u : adj[v])
{
if (u == par[v])
continue;
par[u] = v;
dfs(u);
}
}
const int maxd = 40;
void make_query(int v, int t)
{
int cnt = 0, u = par[v];
ll ans = h[v];
while(u != 0 && cnt <= maxd)
{
for (query cur : task[u])
{
///cout << "check " << v << " : " << u << " : " << cur.t << " : " << t << endl;
if (cur.t <= t && cur.d >= cnt)
ans = (ans * cur.w) % l;
}
cnt ++;
u = par[u];
}
cout << ans << endl;
}
void simulate()
{
for (int i = 1; i <= q; i ++)
{
if (ask[i].type == 2)
make_query(ask[i].ver, i);
else
{
int ver = ask[i].ver, cnt = 0;
while(cnt <= ask[i].d && ver != 0)
{
h[ver] = (h[ver] * ask[i].w) % l;
ver = par[ver];
cnt ++;
}
}
}
}
void solve()
{
input();
offline_queries();
dfs(1);
simulate();
}
int main()
{
speed();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Incorrect |
362 ms |
40824 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Incorrect |
362 ms |
40824 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |