#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 3e5 + 7;
const int INF = 1e9 + 7;
pair<int, int> a[N];
int t[4 * N], lz[4 * N], b[N], ans[N];
int n;
void push(int v, int l, int r) {
  if (l != r) {
    lz[v + v] += lz[v];
    lz[v + v + 1] += lz[v];
  }
  t[v] += lz[v];
  lz[v] = 0;
}
void upd(int v, int l, int r, int ql, int qr, int val) {
  push(v, l, r);
  if (ql <= l && r <= qr) {
    lz[v] = val;
    push(v, l, r);
    return;
  }
  if (qr < l || r < ql) return;
  int mid = (l + r) >> 1;
  upd(v + v, l, mid, ql, qr, val);
  upd(v + v + 1, mid + 1, r, ql, qr, val);
  t[v] = max(t[v + v], t[v + v + 1]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1, greater<pair<int, int> >());
  int l = 0;
  for (int i = 1; i <= n; i++) {
    upd(1, 1, n, 1, a[i].second, 1);
    while (t[1] > 0 && l < n) {
      ans[l] = a[i].first;
      upd(1, 1, n, 1, b[++l], -1);
    }
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
}
