Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define ld long double
- #define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
- #define FORn(i, n) for(ll i=1; i<=(n); i++)
- #define FORx(i, a, b, n) for(ll i=(a); i<=(b); i+=(x))
- #define FORa(i, b) for(i; i<=(b); i++)
- #define FORax(i, b, x) for(i; i<=(b); i+=(x))
- #define FORR(i, a, b) for(ll i=(a); i>=(b); i--)
- #define FORRn(i, n) for(ll i=(n); i>=1; i--)
- #define FORRx(i, a, b, n) for(ll i=(a); i>=(b); i-=(x))
- #define FORRa(i, b) for(i; i>=(b); i--)
- #define FORRax(i, b, x) for(i; i>=(b); i-=(x))
- #define pub(a, x) (a).push_back(x)
- #define puf(a, x) (a).insert((a).begin(), x)
- #define pob(a) (a).pop_back()
- #define pof(a) (a).erase((a).begin())
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (x).size()
- #define sqr(x) (x)*(x)
- #define PI (2*acos(0))
- using namespace std;
- int n, j;
- int main(){
- // freopen("INPUT.inp", "r", stdin);
- // freopen("OUTPUT.out", "w", stdout);
- // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- cin>>n;
- vector<int> h(n+2, 0), r(n+2);
- deque<int> s={n+1};
- h[n+1]=INT_MAX;
- FORn(i, n) cin>>h[i];
- FORRn(i, n){
- while(h[i]>=h[s.front()]) s.pop_front();
- r[i]=s.front();
- s.push_front(i);
- }
- h[n+1]=-1;
- FORn(i, n){
- cin>>j;
- int temp=i;
- while(j--&&temp!=n+1) temp=r[temp];
- cout<<h[temp]<<' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement