// Arup Guha
// 1/13/2017
// Written in contest
// Solution to 2017 January USACO Contest Problem: Promotion Counting

import java.util.*;
import java.io.*;

public class promote {

	public static node[] tree;

	public static void main(String[] args) throws Exception {

		// Open file.
		BufferedReader stdin = new BufferedReader(new FileReader("promote.in"));
		int n = Integer.parseInt(stdin.readLine().trim());
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		int[] vals = new int[n];
		int[] orig = new int[n];

		// original #s + sort
		for (int i=0; i<n; i++) {
			vals[i] = Integer.parseInt(stdin.readLine().trim());
			orig[i] = vals[i];
		}

		Arrays.sort(vals);

		// backwards lookup
		for (int i=0; i<n; i++)
			map.put(vals[i], i);

		// just read in parents.
		int[] par = new int[n-1];
		for (int i=0; i<n-1; i++) par[i] = Integer.parseInt(stdin.readLine().trim());

		// form tree w/o links
		tree = new node[n];
		for (int i=0; i<n; i++) tree[i] = new node(map.get(orig[i]));

		// Add parent links.
		for (int i=0; i<n-1; i++)
			tree[par[i]-1].kids.add(i+1);

		// Store answers here.
		int[] res = new int[n];
		bit myBit = new bit(n);

		// Solve it.
		solve(res, myBit);

		// Store answer.
		StringBuffer sb = new StringBuffer();
		for (int i=0; i<n; i++)
			sb.append(res[i]+"\n");

		// Print it.
		PrintWriter out = new PrintWriter(new FileWriter("promote.out"));
		out.print(sb);
		out.close();
		stdin.close();
	}

	// This is annoying - I like doing tree stuff recursive, but I had to undo the recursion because I blew the stack
	// on their system...
	public static void solve(int[] res, bit myBit) {

		int n = res.length;

		// Set up my own stack...how annoying!
		Stack<Integer> myS = new Stack<Integer>();
		int[] prev = new int[n];
		Arrays.fill(prev, -1);
		int[] cur = new int[n];
		int[] curKid = new int[n];
		myS.push(0);

		// Run till the stack is empty.
		while (myS.size() > 0) {

			// Look at what's at the top, see if we can solve this case.
			int item = myS.peek();
			if (prev[item] == -1) prev[item] = (int)myBit.atOrAbove(tree[item].value+1);

			// Finished iterating through this node's children, evaluate its answer.
			if (curKid[item] == tree[item].kids.size()) {
				cur[item] = (int)myBit.atOrAbove(tree[item].value+1);
				res[item] = cur[item] - prev[item];
				myBit.add(tree[item].value+1, 1);
				myS.pop();
			}

			// A recursive call, push it onto the stack.
			else {
				int next = tree[item].kids.get(curKid[item]);
				curKid[item]++;
				myS.push(next);
			}

		}
	}

}

class node {

	public int value;
	public ArrayList<Integer> kids;

	public node(int x) {
		value = x;
		kids = new ArrayList<Integer>();
	}
}

class bit {

	public long[] cumfreq;

	// Do indexes 1 to n.
	public bit(int n) {

		int size = 1;
		while (size < n) size <<= 1;
		n = size;

		cumfreq = new long[n+1];
	}

	// Uses 1 based indexing.
	public void add(int index, long value) {
		while (index < cumfreq.length) {
			cumfreq[index] += value;
			index += Integer.lowestOneBit(index);
		}
	}

	// Returns the sum of everything upto index.
	public long sum(int index) {
		long ans = 0;
		while (index > 0) {
			ans += cumfreq[index];
			index -= (Integer.lowestOneBit(index));
		}
		return ans;
	}

	// Use 1 based indexing.
	public long sum(int low, int high) {
		return sum(high) - sum(low-1);
	}

	// Return the total number of items in the BIT.
	public long all() {
		return sum(cumfreq.length-1);
	}

	// Return the total number of items in the BIT at or above index.
	public long atOrAbove(int index) {
		long sub = 0;
		if (index > 0) sub = sum(index-1);
		return all() - sub;
	}
}