Advertisement
leminhkt

noname18 (frogs)

Mar 5th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
  5. #define FORn(i, n) for(ll i=1; i<=(n); i++)
  6. #define FORx(i, a, b, n) for(ll i=(a); i<=(b); i+=(x))
  7. #define FORa(i, b) for(i; i<=(b); i++)
  8. #define FORax(i, b, x) for(i; i<=(b); i+=(x))
  9. #define FORR(i, a, b) for(ll i=(a); i>=(b); i--)
  10. #define FORRn(i, n) for(ll i=(n); i>=1; i--)
  11. #define FORRx(i, a, b, n) for(ll i=(a); i>=(b); i-=(x))
  12. #define FORRa(i, b) for(i; i>=(b); i--)
  13. #define FORRax(i, b, x) for(i; i>=(b); i-=(x))
  14. #define pub(a, x) (a).push_back(x)
  15. #define puf(a, x) (a).insert((a).begin(), x)
  16. #define pob(a) (a).pop_back()
  17. #define pof(a) (a).erase((a).begin())
  18. #define all(x) (x).begin(), (x).end()
  19. #define sz(x) (x).size()
  20. #define sqr(x) (x)*(x)
  21. #define PI (2*acos(0))
  22. using namespace std;
  23.  
  24. int n, j;
  25. int main(){
  26.     // freopen("INPUT.inp", "r", stdin);
  27.     // freopen("OUTPUT.out", "w", stdout);
  28.     // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  29.     cin>>n;
  30.     vector<int> h(n+2, 0), r(n+2);
  31.     deque<int> s={n+1};
  32.     h[n+1]=INT_MAX;
  33.     FORn(i, n) cin>>h[i];
  34.     FORRn(i, n){
  35.         while(h[i]>=h[s.front()]) s.pop_front();
  36.         r[i]=s.front();
  37.         s.push_front(i);
  38.     }
  39.     h[n+1]=-1;
  40.     FORn(i, n){
  41.         cin>>j;
  42.         int temp=i;
  43.         while(j--&&temp!=n+1) temp=r[temp];
  44.         cout<<h[temp]<<' ';
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement