File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+
5+ #define ll long long
6+ #define pb push_back
7+ #define ppb pop_back
8+ #define F first
9+ #define S second
10+ #define fr (a, b ) for (ll i = a; i < b; i++)
11+ typedef pair<int , int > pii;
12+ typedef pair<ll, ll> pl;
13+ typedef vector<int > vi;
14+ typedef vector<ll> vl;
15+ typedef vector<pii> vpii;
16+ typedef vector<pl> vpl;
17+ typedef vector<vi> vvi;
18+ typedef vector<vl> vvl;
19+
20+ void init ();
21+
22+ int main (){
23+ init ();
24+ int t;
25+ cin>>t;
26+ while (t--){
27+ int n,t=-1 ;
28+ stack<int > s;
29+ cin>>n;
30+ int arr[n];
31+ fr (0 ,n){
32+ cin>>arr[i];
33+ }
34+
35+ fr (0 ,n){
36+
37+ while (!s.empty ()){
38+ if (s.top ()<arr[i]){
39+ t=s.top ();
40+ break ;
41+ }
42+ else s.pop ();
43+
44+ }
45+ s.push (arr[i]);
46+ cout<<t<<" " ;
47+ t=-1 ;
48+ }
49+ cout<<endl;
50+ }
51+
52+ return 0 ;
53+ }
54+
55+
56+ void init () {
57+ // int i, j, n, m;
58+ #ifndef ONLINE_JUDGE
59+ freopen (" input.txt" , " r" , stdin);
60+ // freopen("output.txt", "w", stdout);
61+ #endif
62+ }
You can’t perform that action at this time.
0 commit comments