#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 100005;
multiset<long long> s[N], S;
long long ans[N], t[N];
int f[N], d[N];
inline long long lzy(int x) { return t[x] / d[x]; }
void insset(int x) {
  if (s[x].size()) {
    S.insert(*s[x].begin() + lzy(x));
    S.insert(*s[x].rbegin() + lzy(x));
  }
}
void eraset(int x) {
  if (s[x].size()) {
    S.erase(S.find(*s[x].begin() + lzy(x)));
    S.erase(S.find(*s[x].rbegin() + lzy(x)));
  }
}
void insdd(int x) {
  eraset(f[x]);
  s[f[x]].insert(ans[x]);
  insset(f[x]);
}
void eradd(int x) {
  eraset(f[x]);
  s[f[x]].erase(s[f[x]].find(ans[x]));
  insset(f[x]);
}
void inc(int x, long long y, long long z) {
  eradd(x);
  ans[x] +=
      y + (t[x] - t[x] / (d[x] + 1) * d[x]) - (t[x] - t[x] / d[x] * (d[x] - 1));
  insdd(x);
  long long de = t[x] / (d[x] + 1) - t[x] / d[x];
  eraset(x);
  s[x].insert(z);
  d[x]++;
  insset(x);
  eradd(f[x]);
  ans[f[x]] += de;
  insdd(f[x]);
}
void dec(int x, long long y, long long z) {
  eradd(x);
  ans[x] += y + (t[x] - t[x] / (d[x] - 1) * (d[x] - 2)) -
            (t[x] - t[x] / d[x] * (d[x] - 1));
  insdd(x);
  long long de = t[x] / (d[x] - 1) - t[x] / d[x];
  eraset(x);
  s[x].erase(s[x].find(z));
  d[x]--;
  insset(x);
  eradd(f[x]);
  ans[f[x]] += de;
  insdd(f[x]);
}
int main() {
  int n = read(), q = read();
  for (int i = (int)(1); i <= (int)(n); i++) t[i] = read();
  for (int i = (int)(1); i <= (int)(n); i++) {
    f[i] = read();
    d[f[i]]++;
    d[i] += 2;
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    long long zs = t[i] / d[i];
    ans[f[i]] += zs;
    ans[i] += t[i] - (d[i] - 1) * zs;
  }
  for (int i = (int)(1); i <= (int)(n); i++) s[f[i]].insert(ans[i]);
  for (int i = (int)(1); i <= (int)(n); i++) insset(i);
  for (int i = (int)(1); i <= (int)(q); i++) {
    int op = read();
    if (op == 1) {
      int x = read(), y = read();
      dec(f[x], -lzy(x), ans[x]);
      f[x] = y;
      inc(f[x], lzy(x), ans[x]);
    } else if (op == 2) {
      int x = read();
      writeln(ans[x] + lzy(f[x]));
    } else {
      wri(*S.begin());
      writeln(*S.rbegin());
    }
  }
}
