Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int mxn = 2e5;
- //#define Kin
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- #ifdef Kin
- (void)!freopen("input.txt", "r", stdin);
- (void)!freopen("output.txt", "w", stdout);
- #endif
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- cin >> n;
- vector<long long> res(n, -1);
- stack<pair<int, long long>> s;
- for (int i = 0; i < n; i++)
- {
- long long k;
- cin >> k;
- while (!s.empty() && s.top().second < k)
- {
- res[s.top().first] = k;
- s.pop();
- }
- s.push(make_pair(i, k));
- }
- for (long long i = 0; i < n; i++)
- cout << res[i] << ' ';
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement