#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int maxi = 2e6;
const int sz = 1 << 19;
int p[maxi];
int q[maxi];
int n;
int tree[maxi];
pair<int, int> treeL[maxi];
int lazy[maxi];
int bit[maxi];
int rez[maxi];
int cnt[maxi];
int poz[maxi];
void bit_update(int x, int val) {
  for (int i = x; i < maxi; i += i & -i) bit[i] += val;
}
int bit_get(int x) {
  int ans = 0;
  for (int i = x; i > 0; i -= i & -i) ans += bit[i];
  return ans;
}
void build() {
  for (int i = 1; i < 2 * sz; i++) treeL[i] = {inf, i};
  for (int i = sz; i < 2 * sz; i++) tree[i] = p[i - sz + 1];
  for (int i = sz - 1; i > 0; i--) tree[i] = max(tree[2 * i], tree[2 * i + 1]);
}
int get_max(int node, int tl, int tr, int l, int r) {
  if (tl >= l && tr <= r) return tree[node];
  if (tl > r || tr < l) return -inf;
  int mid = (tl + tr) / 2;
  int val1 = get_max(2 * node, tl, mid, l, r);
  int val2 = get_max(2 * node + 1, mid + 1, tr, l, r);
  return max(val1, val2);
}
void update(int x) {
  x += sz - 1;
  tree[x] = -inf;
  x /= 2;
  while (x) {
    tree[x] = max(tree[2 * x], tree[2 * x + 1]);
    x /= 2;
  }
}
void push(int node) {
  if (node >= sz)
    treeL[node].first += lazy[node];
  else {
    lazy[2 * node] += lazy[node];
    lazy[2 * node + 1] += lazy[node];
  }
  lazy[node] = 0;
}
void check(int node) {
  if (node >= sz) return;
  pair<int, int> val1 = {treeL[2 * node].first + lazy[2 * node],
                         treeL[2 * node].second};
  pair<int, int> val2 = {treeL[2 * node + 1].first + lazy[2 * node + 1],
                         treeL[2 * node + 1].second};
  treeL[node] = min(val1, val2);
}
void lazy_update(int node, int tl, int tr, int l, int r, int val) {
  push(node);
  if (tl > r || tr < l) {
    check(node);
    return;
  }
  if (tl >= l && tr <= r) {
    lazy[node] += val;
    push(node);
    check(node);
    return;
  }
  int mid = tl + tr >> 1;
  lazy_update(2 * node, tl, mid, l, r, val);
  lazy_update(2 * node + 1, mid + 1, tr, l, r, val);
  check(node);
  return;
}
pair<int, int> lazy_get(int node, int tl, int tr, int l, int r) {
  push(node);
  if (tl > r || tr < l) return {inf, inf};
  if (tl >= l && tr <= r)
    return {treeL[node].first + lazy[node], treeL[node].second};
  int mid = tl + tr >> 1;
  pair<int, int> val1 = lazy_get(2 * node, tl, mid, l, r);
  pair<int, int> val2 = lazy_get(2 * node + 1, mid + 1, tr, l, r);
  pair<int, int> val = min(val1, val2);
  return {val.first + lazy[node], val.second};
}
void set_x(int node, int tl, int tr, int poz, int val) {
  push(node);
  if (tl == tr) {
    treeL[node] = {val, node - sz + 1};
    return;
  }
  int mid = tl + tr >> 1;
  if (poz <= mid)
    set_x(2 * node, tl, mid, poz, val);
  else
    set_x(2 * node + 1, mid + 1, tr, poz, val);
  check(node);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    poz[p[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &q[i]);
  }
  for (int i = n + 1; i <= sz; i++) p[i] = -inf;
  build();
  rez[1] = n;
  int cur = n;
  for (int i = 1; i < n; i++) {
    int x = bit_get(q[i]);
    set_x(1, 1, sz, q[i], x);
    lazy_update(1, 1, sz, q[i], n, -1);
    pair<int, int> val = lazy_get(1, 1, sz, q[i], n);
    int rem = get_max(1, 1, sz, 1, val.second);
    cnt[rem] = 1;
    update(poz[rem]);
    lazy_update(1, 1, sz, poz[rem], n, 1);
    bit_update(q[i], -1);
    bit_update(poz[rem], 1);
    while (cnt[cur]) cur--;
    rez[i + 1] = cur;
  }
  for (int i = 1; i <= n; i++) printf("%d ", rez[i]);
  printf("\n");
  return 0;
}
