Advertisement
Guest User

CDVR3.3

a guest
Oct 28th, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int mxn = 2e5;
  4.                                     //#define Kin
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.  
  11. #ifdef Kin
  12.     (void)!freopen("input.txt", "r", stdin);
  13.     (void)!freopen("output.txt", "w", stdout);
  14. #endif
  15.  
  16.     int t;
  17.     cin >> t;
  18.     while (t--)
  19.     {
  20.         int n;
  21.         cin >> n;
  22.         vector<long long> res(n, -1);
  23.         stack<pair<int, long long>> s;
  24.         for (int i = 0; i < n; i++)
  25.         {
  26.             long long k;
  27.             cin >> k;
  28.             while (!s.empty() && s.top().second < k)
  29.             {
  30.                 res[s.top().first] = k;
  31.                 s.pop();
  32.             }
  33.             s.push(make_pair(i, k));
  34.         }
  35.         for (long long i = 0; i < n; i++)
  36.             cout << res[i] << ' ';
  37.         cout << '\n';
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement