#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 3e5;
int n, p[N_MAX], q[N_MAX], dead[N_MAX], ans[N_MAX + 1], pp[N_MAX];
bool in_dead[N_MAX];
int lazy[N_MAX], d[N_MAX], g[N_MAX];
void push_down(int a, int b) {
  int k = (a + b) / 2;
  if (a == k)
    d[k] += lazy[k];
  else {
    g[(a + k) / 2] += lazy[k];
    lazy[(a + k) / 2] += lazy[k];
  }
  if (k + 1 == b)
    d[k + 1] += lazy[k];
  else {
    g[(k + 1 + b) / 2] += lazy[k];
    lazy[(k + 1 + b) / 2] += lazy[k];
  }
  lazy[k] = 0;
}
void update(int a, int b, int i, int j, int dif) {
  if (a == b) {
    d[a] += dif;
    return;
  }
  int k = (a + b) / 2;
  if (a == i && b == j) {
    g[k] += dif;
    lazy[k] += dif;
    return;
  }
  if (lazy[k]) push_down(a, b);
  if (j <= k)
    update(a, k, i, j, dif);
  else if (k + 1 <= i)
    update(k + 1, b, i, j, dif);
  else {
    update(a, k, i, k, dif);
    update(k + 1, b, k + 1, j, dif);
  }
  g[k] = max((a == k ? d[a] : g[(a + k) / 2]),
             (k + 1 == b ? d[b] : g[(k + 1 + b) / 2]));
}
int lb(int a, int b) {
  if (a == b) return a;
  push_down(a, b);
  int k = (a + b) / 2;
  if ((a == k ? d[k] : g[(a + k) / 2]) > 0)
    return lb(a, k);
  else
    return lb(k + 1, b);
}
int f[N_MAX];
int init(int a, int b) {
  if (a == b) return a;
  int k = (a + b) / 2;
  int i1 = init(a, k), i2 = init(k + 1, b);
  return f[k] = (p[i1] > p[i2] ? i1 : i2);
}
int max_query(int a, int b, int i, int j) {
  if (i == j) return i;
  int k = (a + b) / 2;
  if (a == i && b == j) return f[k];
  if (j <= k) return max_query(a, k, i, j);
  if (k + 1 <= i) return max_query(k + 1, b, i, j);
  int q1 = max_query(a, k, i, k), q2 = max_query(k + 1, b, k + 1, j);
  return (p[q1] > p[q2] ? q1 : q2);
}
int del(int a, int b, int i) {
  if (a == b) {
    p[i] = 0;
    return i;
  }
  int k = (a + b) / 2;
  int q1, q2;
  if (i <= k) {
    q1 = del(a, k, i);
    q2 = (k + 1 == b ? k + 1 : f[(k + 1 + b) / 2]);
  } else {
    q1 = (a == k ? k : f[(a + k) / 2]);
    q2 = del(k + 1, b, i);
  }
  return f[k] = (p[q1] > p[q2] ? q1 : q2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) pp[i] = p[i];
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
  }
  init(0, n - 1);
  for (int i = 0; i < n - 1; i++) {
    update(0, n - 1, q[i], n - 1, 1);
    int x = lb(0, n - 1);
    dead[i] = max_query(0, n - 1, 0, x);
    update(0, n - 1, dead[i], n - 1, -1);
    del(0, n - 1, dead[i]);
  }
  for (int i = 0; i < n - 1; i++) in_dead[dead[i]] = true;
  for (int i = 0; i < n; i++)
    if (!in_dead[i]) dead[n - 1] = i;
  ans[n] = 0;
  for (int i = n - 1; 0 <= i; i--) ans[i] = max(ans[i + 1], pp[dead[i]]);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
