-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsol.cpp
62 lines (52 loc) · 1.27 KB
/
sol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define sqr(x) (x) * (x)
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define prec(x) fixed<<setprecision(x)
#define testcase cout << "Case " << tc++ << ": "
#define unsyncIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
using namespace std;
using ll = long long;
using lll = __int128_t;
using ld = long double;
using ull = unsigned long long;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const ld PI = acos(-1.0);
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const int N = 2e5 + 5;
int tc = 1;
int n, a[N], Left[N], right[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
stack<int> leftStack, rightStack;
leftStack.push(0);
for (int i = 1; i <= n; i ++) {
while (!leftStack.empty() and a[leftStack.top()] >= a[i]) {
leftStack.pop();
}
debug(leftStack);
Left[i] = leftStack.top();
leftStack.push(i);
}
for (int i = 1; i <= n; i++) {
cout << Left[i] << ' ';
}
}
int main() {
unsyncIO;
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}