#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn], p[maxn], n;
pair<int, int> val[maxn << 2], s[maxn << 2];
void push_up(int rt) { val[rt] = max(val[rt << 1], val[rt << 1 | 1]); }
void build(int l, int r, int rt) {
  if (l == r) {
    val[rt].first = a[l];
    val[rt].second = l;
    return;
  }
  int m = l + r >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  push_up(rt);
}
pair<int, int> query(int l, int r, int rt, int L, int R) {
  if (L <= l && R >= r) return val[rt];
  int m = l + r >> 1;
  pair<int, int> res = {0, 0};
  if (L <= m) res = max(res, query(l, m, rt << 1, L, R));
  if (m < R) res = max(res, query(m + 1, r, rt << 1 | 1, L, R));
  return res;
}
void update(int l, int r, int rt, int x, int v) {
  if (l == r) {
    val[rt].first = v;
    return;
  }
  int m = l + r >> 1;
  if (x <= m)
    update(l, m, rt << 1, x, v);
  else
    update(m + 1, r, rt << 1 | 1, x, v);
  push_up(rt);
}
void update2(int l, int r, int rt, int x, int v) {
  if (l == r) {
    s[rt] = {v, x};
    return;
  }
  int m = l + r >> 1;
  if (x <= m)
    update2(l, m, rt << 1, x, v);
  else
    update2(m + 1, r, rt << 1 | 1, x, v);
  s[rt] = max(s[rt << 1], s[rt << 1 | 1]);
}
pair<int, int> query2(int l, int r, int rt, int L, int R) {
  if (L <= l && R >= r) return s[rt];
  int m = l + r >> 1;
  pair<int, int> res = {0, 0};
  if (L <= m) res = max(res, query2(l, m, rt << 1, L, R));
  if (m < R) res = max(res, query2(m + 1, r, rt << 1 | 1, L, R));
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) scanf("%d", p + i);
  build(1, n, 1);
  printf("%d", val[1].first);
  for (int i = 1; i < n; ++i) {
    pair<int, int> lst = query2(1, n, 1, 1, p[i]), t;
    while (lst.first > p[i]) {
      update2(1, n, 1, lst.second, p[i]);
      p[i] = lst.first;
      lst = query2(1, n, 1, 1, p[i]);
    }
    t = query(1, n, 1, 1, p[i]);
    update2(1, n, 1, t.second, p[i]);
    update(1, n, 1, t.second, 0);
    printf(" %d", val[1].first);
  }
  return 0;
}
