#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 10, mod = int(1e9) + 7;   const long long inf = (long long)(2e18);   int n, q;   vector<int> g[N];   int first[N], c[N];   long long t[N], a[N], b[N], add[N];   set<pair<long long, int> > all;   multiset<long long> st[N];   set<pair<long long, int> >::iterator it;   multiset<long long>::iterator is;   long long mn, mx;   int p[N], pn;   void globaldel(int i) {     if (st[i].size() > 0) {       it = all.find(make_pair(*st[i].begin() + add[i], i));       if (it != all.end()) all.erase(it);       it = all.find(make_pair(*st[i].rbegin() + add[i], i));       if (it != all.end()) all.erase(it);     }   }   void globaladd(int i) {     if (st[i].size() > 0) {       all.insert(make_pair(*st[i].begin() + add[i], i));       all.insert(make_pair(*st[i].rbegin() + add[i], i));     }   }   void Del(int i) {     globaldel(first[i]);     st[first[i]].erase(st[first[i]].find(a[i]));     globaladd(first[i]);   }   void Add(int i) {     globaldel(first[i]);     st[first[i]].insert(a[i]);     globaladd(first[i]);   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %I64d , &t[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &first[i]);       g[first[i]].push_back(i);       c[first[i]]++;     }     for (int i = 1; i <= n; i++) {       long long val = t[i] / (c[i] + 2);       b[i] = t[i] - (c[i] + 1) * val;       a[i] += b[i];       for (int j = 0; j < g[i].size(); j++) {         int to = g[i][j];         a[to] += val;       }       a[first[i]] += val;     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         int to = g[i][j];         st[i].insert(a[to]);       }       if (st[i].size() > 0) {         all.insert(make_pair(*st[i].rbegin(), i));         all.insert(make_pair(*st[i].begin(), i));       }     }     int tp, i, j;     for (int qq = 1; qq <= q; qq++) {       scanf( %d , &tp);       if (tp == 1) {         scanf( %d%d , &i, &j);         Del(i);         Del(j);         Del(first[j]);         globaldel(j);         a[j] -= b[j];         c[j]++;         long long val = t[j] / (c[j] + 2);         a[i] += t[j] / (c[j] + 1);         ;         b[j] = t[j] - (c[j] + 1) * val;         a[j] += b[j];         val -= t[j] / (c[j] + 1);         a[i] -= add[j];         add[j] += val;         a[first[j]] += val;         a[j] += t[i] / (c[i] + 2);         a[i] += add[first[i]];         Add(j);         Add(first[j]);         int v = first[i];         Del(v);         Del(first[v]);         globaldel(v);         first[i] = j;         a[i] -= t[v] / (c[v] + 2);         a[v] -= t[i] / (c[i] + 2);         a[v] -= b[v];         c[v]--;         val = t[v] / (c[v] + 2);         b[v] = t[v] - (c[v] + 1) * val;         a[v] += b[v];         val -= t[v] / (c[v] + 3);         add[v] += val;         a[first[v]] += val;         Add(i);         Add(v);         Add(first[v]);         globaladd(j);         globaladd(v);       } else if (tp == 2) {         scanf( %d , &i);         printf( %I64d n , a[i] + add[first[i]]);       } else {         printf( %I64d %I64d n , (*all.begin()).first, (*all.rbegin()).first);       }     }     return 0;   }