1178_G. The Awesomest Vertex

You are given a rooted tree on n vertices. The vertices are numbered from 1 to n; the root is the vertex number 1.

Each vertex has two integers associated with it: a_i and b_i. We denote the set of all ancestors of v (including v itself) by R(v). The awesomeness of a vertex v is defined as 

$$$\left| ∑_{w ∈ R(v)} a_w\right| ⋅ \left|∑_{w ∈ R(v)} b_w\right|,$$$

where |x| denotes the absolute value of x. 

Process q queries of one of the following forms: 

  * 1 v x — increase a_v by a positive integer x. 
  * 2 v — report the maximum awesomeness in the subtree of vertex v. 

Input

The first line contains two integers n and q (1 ≤ n ≤ 2⋅ 10^5, 1 ≤ q ≤ 10^5) — the number of vertices in the tree and the number of queries, respectively.

The second line contains n - 1 integers p_2, p_3, ..., p_n (1 ≤ p_i < i), where p_i means that there is an edge between vertices i and p_i.

The third line contains n integers a_1, a_2, ..., a_n (-5000 ≤ a_i ≤ 5000), the initial values of a_i for each vertex.

The fourth line contains n integers b_1, b_2, ..., b_n (-5000 ≤ b_i ≤ 5000), the values of b_i for each vertex.

Each of the next q lines describes a query. It has one of the following forms: 

  * 1 v x (1 ≤ v ≤ n, 1≤ x ≤ 5000). 
  * 2 v (1 ≤ v ≤ n). 

Output

For each query of the second type, print a single line with the maximum awesomeness in the respective subtree.

Example

Input

5 6
1 1 2 2
10 -3 -7 -3 -10
10 3 9 3 6
2 1
2 2
1 2 6
2 1
1 2 5
2 1


Output

100
91
169
240

Note

The initial awesomeness of the vertices is [100, 91, 57, 64, 57]. The most awesome vertex in the subtree of vertex 1 (the first query) is 1, and the most awesome vertex in the subtree of vertex 2 (the second query) is 2. 

After the first update (the third query), the awesomeness changes to [100, 169, 57, 160, 57] and thus the most awesome vertex in the whole tree (the fourth query) is now 2.

After the second update (the fifth query), the awesomeness becomes [100, 234, 57, 240, 152], hence the most awesome vertex (the sixth query) is now 4. 

Example input:
5 6
1 1 2 2
10 -3 -7 -3 -10
10 3 9 3 6
2 1
2 2
1 2 6
2 1
1 2 5
2 1


Example output:
100
91
169
240


Tags: data structures
dfs and similar
Difficulty rating: 3000

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
const ll inf = LLONG_MAX;
int n, q, a[N], b[N];
vector<int> G[N];
int in[N], out[N], num[N], id;
void dfs(int u, int fa) {
  in[u] = ++id;
  num[id] = u;
  for (auto v : G[u]) {
    if (v == fa) continue;
    a[v] += a[u];
    b[v] += b[u];
    dfs(v, u);
  }
  out[u] = id;
}
struct Line {
  ll k, b, x;
  ll eval() const { return k * x + b; }
  bool cmp(const Line& oth) const {
    ll x1 = eval(), x2 = oth.eval();
    if (x1 != x2) return x1 > x2;
    return k > oth.k;
  }
  ll isect(const Line& oth) { return (eval() - oth.eval()) / (oth.k - k) + 1; }
};
struct seg {
  int l, r;
  Line L;
  ll wait, tag;
} t[N << 3];
void setv(int p, ll add) {
  t[p].L.x += add;
  t[p].tag += add;
  t[p].wait -= add;
}
void pushup(int p) {
  auto l1 = t[p << 1].L, l2 = t[p << 1 | 1].L;
  if (!l1.cmp(l2)) swap(l1, l2);
  t[p].L = l1;
  t[p].wait = min(t[p << 1].wait, t[p << 1 | 1].wait);
  if (l1.k < l2.k) t[p].wait = min(t[p].wait, l1.isect(l2));
}
void pushdown(int p) {
  setv(p << 1, t[p].tag), setv(p << 1 | 1, t[p].tag);
  t[p].tag = 0;
}
void build(int p, int l, int r) {
  t[p].l = l, t[p].r = r, t[p].wait = 0;
  if (l == r) {
    int x = num[(l + 1) / 2];
    if (l & 1)
      t[p].L = {b[x], 1ll * a[x] * b[x], 0};
    else
      t[p].L = {-b[x], -1ll * a[x] * b[x], 0};
    t[p].wait = inf;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void upd(int p, int x, int y, ll add) {
  int l = t[p].l, r = t[p].r;
  if (l >= x && r <= y && t[p].wait > add) {
    setv(p, add);
    return;
  }
  if (t[p].tag) pushdown(p);
  int mid = (l + r) >> 1;
  if (x <= mid) upd(p << 1, x, y, add);
  if (y > mid) upd(p << 1 | 1, x, y, add);
  pushup(p);
}
ll qry(int p, int x, int y) {
  int l = t[p].l, r = t[p].r;
  if (l >= x && r <= y) return t[p].L.eval();
  if (t[p].tag) pushdown(p);
  int mid = (l + r) >> 1;
  ll ans = 0;
  if (x <= mid) ans = max(ans, qry(p << 1, x, y));
  if (y > mid) ans = max(ans, qry(p << 1 | 1, x, y));
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 2; i <= n; i++) {
    int fa;
    scanf("%d", &fa);
    G[fa].push_back(i);
  }
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) scanf("%d", b + i);
  dfs(1, 0);
  build(1, 1, 2 * n);
  while (q--) {
    int op, v;
    scanf("%d%d", &op, &v);
    if (op == 1) {
      ll x;
      scanf("%lld", &x);
      upd(1, in[v] * 2 - 1, out[v] * 2, x);
    } else
      printf("%lld\n", qry(1, in[v] * 2 - 1, out[v] * 2));
  }
  return 0;
}