CSES – List Removals

PBDS

#include<bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
//declare
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>;
int n;
//
signed main(){
    fastio;
    cin>>n;
    ordered_set st;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        st.insert({i,x});
    }
    while(n--){
        int x; cin>>x; x--;
        auto it = st.find_by_order(x);
        cout << it->s << " ";
        st.erase(it);
    }
    cout<<"\n";
    return 0;
}

相關文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *