func_code_string: #include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx )   using namespace std;   const int MAXSIZE = 10000020;   int bufpos;   char buf[MAXSIZE];   void init() {     buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ;     bufpos = 0;   }   int readint() {     int val = 0;     for (; !isdigit(buf[bufpos]); bufpos++)       ;     for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ;     return val;   }   char readchar() {     for (; isspace(buf[bufpos]); bufpos++)       ;     return buf[bufpos++];   }   int readstr(char *s) {     int cur = 0;     for (; isspace(buf[bufpos]); bufpos++)       ;     for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];     s[cur] =   0 ;     return cur;   }   char bf[1 << 25], st[20], *w = bf;   void flush() {     fwrite(bf, 1, w - bf, stdout);     w = bf;   }   inline void pc(register char c) { *w++ = c; }   void print(register int n) {     register char *t = st;     do {       *t++ = n % 10 + 48;     } while (n /= 10);     while (t-- > st) pc(*t);   }   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     init();     n = readint();     q = readint();     for (int i = 1; i <= n; ++i) {       aa[i] = readint();     }     for (int i = 2; i <= n; ++i) {       fa[i] = readint();       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];       kh[i] = -50001;     }     for (int i = 1; i <= q; ++i) {       int x = readint();       int y = siz[x];       x = fp[x];       int pp = i + 1, gg = y >> 3, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j < gg; ++j, jj += 8, diao += 8, aa += 8) {         int w;         w = jj[0] + aa[0] < pp, jj[0] = w ? i : jj[0], ans += w * diao[0],         cnt += w;         w = jj[1] + aa[1] < pp, jj[1] = w ? i : jj[1], ans += w * diao[1],         cnt += w;         w = jj[2] + aa[2] < pp, jj[2] = w ? i : jj[2], ans += w * diao[2],         cnt += w;         w = jj[3] + aa[3] < pp, jj[3] = w ? i : jj[3], ans += w * diao[3],         cnt += w;         w = jj[4] + aa[4] < pp, jj[4] = w ? i : jj[4], ans += w * diao[4],         cnt += w;         w = jj[5] + aa[5] < pp, jj[5] = w ? i : jj[5], ans += w * diao[5],         cnt += w;         w = jj[6] + aa[6] < pp, jj[6] = w ? i : jj[6], ans += w * diao[6],         cnt += w;         w = jj[7] + aa[7] < pp, jj[7] = w ? i : jj[7], ans += w * diao[7],         cnt += w;       }       gg <<= 3;       for (int j = gg; j < y; ++j) {         int w;         w = jj[j - gg] + aa[j - gg] < pp, jj[j - gg] = w ? i : jj[j - gg],         ans += w * diao[j - gg], cnt += w;         ;       }       ans = ans - cnt * dd[x];       print(ans);       pc(   );       print(cnt);       pc(  n );     }     flush();   }   