Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define el endl
- #define umi unordered_map<int, int>
- #define umll unordered_map<ll, ll>
- #define all(vect) vect.begin(), vect.end()
- #define reset(A) memset(A, 0, sizeof(A))
- const int mod = 1e9 + 7;
- using namespace std;
- void solve()
- {
- int n;
- cin >> n;
- int a[n + 5];
- stack<int> st;
- umi mp;
- for(int i = 0; i < n; i++)
- {
- cin >> a[i];
- mp[i]++;
- }
- st.push(0);
- for(int i = 1; i < n; i++)
- {
- while(a[i] >= a[st.top()] && !st.empty())
- {
- mp[i] += mp[st.top()];
- st.pop();
- }
- st.push(i);
- }
- for(int i = 0; i < n; i++)
- {
- cout << mp[i]<< " ";
- }
- cout << el;
- }
- int main()
- {
- int t = 1;
- cin >> t;
- // cin.ignore();
- while(t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement