Alex_tz307

Nearest smaller value

Sep 14th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long N, x;
  6. vector < int > a, v;
  7.  
  8. int main () {
  9.   cin >> N;
  10.   a = v = vector < int > (N + 1);
  11.   for (int i = 0; i < N; i ++) {
  12.     cin >> a[i];
  13.     v[i] = i - 1;
  14.     cout << v[i] << ' ';
  15.     while (~v[i] && a[v[i]] >= a[i])
  16.       v[i] = v[v[i]], cout << v[i] << ' ';
  17.     cout << '\n';
  18.   }
  19.   return 0;
  20. }
  21. s
Advertisement
Add Comment
Please, Sign In to add comment