#include // {{{ // https://codeforces.com/blog/entry/96344 #pragma GCC optimize("O2,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; template [[nodiscard]] static T MIN() { return std::numeric_limits::min(); } template [[nodiscard]] static T MAX() { return std::numeric_limits::max(); } template [[nodiscard]] static T sc(auto&& x) { return static_cast(x); } template [[nodiscard]] static T sz(auto&& x) { return static_cast(x.size()); } #define prln(...) std::println(__VA_ARGS__) #define pr(...) std::print(__VA_ARGS__) #ifdef LOCAL #define dbgln(...) std::println(__VA_ARGS__) #define dbg(...) std::print(__VA_ARGS__) #endif using ll = long long; using ld = long double; template using v = std::vector; template using r = std::array; template using p = std::pair; #define ff first #define ss second #define eb emplace_back #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() // }}} template struct fenwick_tree { public: explicit fenwick_tree(size_t n) : tree(n, 1) { for (size_t i = 0; i < tree.size(); ++i) { size_t j = g(i); if (j < tree.size()) { tree[j] += tree[i]; } } } T const query(int i) const { if (!(0 <= i && i < static_cast(tree.size()))) { throw std::out_of_range("cannot query fenwick tree of size " + std::to_string(tree.size()) + " at index " + std::to_string(i)); } T t = sentinel(); for (int j = static_cast(i); j >= 0; j = h(j) - 1) { t = merge(t, tree[j]); } return t; }; T const query(int l, int r) const { if (!(0 <= l && l <= r && r < static_cast(tree.size()))) { throw std::out_of_range( "cannot query fenwick tree of size " + std::to_string(tree.size()) + " at range [" + std::to_string(l) + ", " + std::to_string(r) + "]"); } if (l == 0) { return query(r); } return unmerge(query(r), query(l - 1)); }; void update(int i, T const& t) noexcept { assert(0 <= i && i < static_cast(tree.size())); for (size_t j = i; j < tree.size(); j = g(j)) { tree[j] = merge(tree[j], t); } } private: [[nodiscard]] inline T merge(T const& x, T const& y) const noexcept { return x + y; } [[nodiscard]] inline T unmerge(T const& x, T const& y) const noexcept { return x - y; } [[nodiscard]] inline T sentinel() const noexcept { return 0; } [[nodiscard]] inline size_t g(size_t i) const noexcept { return i | (i + 1); } [[nodiscard]] inline size_t h(size_t i) const noexcept { return i & (i + 1); } std::vector tree; }; #include #include using namespace __gnu_pbds; // https://mirror.codeforces.com/blog/entry/124683 namespace hashing { using i64 = std::int64_t; using u64 = std::uint64_t; static const u64 FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); #if USE_AES std::mt19937 rd(FIXED_RANDOM); const __m128i KEY1{(i64)rd(), (i64)rd()}; const __m128i KEY2{(i64)rd(), (i64)rd()}; #endif template struct custom_hash {}; template inline void hash_combine(u64& seed, T const& v) { custom_hash hasher; seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); }; template struct custom_hash::value>::type> { u64 operator()(T _x) const { u64 x = _x; #if USE_AES __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; __m128i y = _mm_aesenc_si128(m, KEY1); __m128i z = _mm_aesenc_si128(y, KEY2); return z[0]; #else x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); #endif } }; template struct custom_hash()))>> { u64 operator()(T const& a) const { u64 value = FIXED_RANDOM; for (auto& x : a) hash_combine(value, x); return value; } }; template struct custom_hash> { u64 operator()(const std::tuple& a) const { u64 value = FIXED_RANDOM; std::apply( [&value](T const&... args) { (hash_combine(value, args), ...); }, a); return value; } }; template struct custom_hash> { u64 operator()(std::pair const& a) const { u64 value = FIXED_RANDOM; hash_combine(value, a.first); hash_combine(value, a.second); return value; } }; }; // namespace hashing #ifdef PB_DS_ASSOC_CNTNR_HPP template using hashtable = gp_hash_table< Key, Value, hashing::custom_hash, std::equal_to, direct_mask_range_hashing<>, linear_probe_fn<>, hash_standard_resize_policy, hash_load_check_resize_trigger<>, true>>; #endif #ifdef PB_DS_TREE_POLICY_HPP template using multitree = tree, rb_tree_tag, tree_order_statistics_node_update>; template using rbtree = tree, rb_tree_tag, tree_order_statistics_node_update>; #endif void solve() { int n; cin >> n; v a(n); rbtree t; for (int i = 0; i < n; ++i) { cin >> a[i]; t.insert(i); } // fenwick_tree fw(n); int p; for (int i = 0; i < n; ++i) { cin >> p; --p; int ans = *t.find_by_order(p); t.erase(ans); cout << a[ans] << ' '; // int l = 0, r = n - 1; // while (l <= r) { // int m = l + (r - l) / 2; // int q = fw.query(m); // if (q >= p) { // r = m - 1; // } else if (q < p) { // l = m + 1; // } // } // cout << a[l] << ' '; // // fw.update(l, -1); } } int main() { // {{{ cin.tie(nullptr)->sync_with_stdio(false); int t = 1; // cin >> t; while (t--) { solve(); } return 0; } // }}}