-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Card_Deck.cpp
More file actions
52 lines (51 loc) · 1.06 KB
/
B_Card_Deck.cpp
File metadata and controls
52 lines (51 loc) · 1.06 KB
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
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
ll p[n];
for(int i=0;i<n;i++){
cin>>p[i];
}
vector<ll> ans;
ll mq=n;
// for(int i=n;i>=1;i--){
// mq.push(n);
// }
ll i=n-1;
unordered_map<ll,ll> m;
while(i>=0){
stack<ll> s;
while(m.count(mq)>0){
mq--;
}
while(i>=0 && p[i]!=mq){
m[p[i]]++;
s.push(p[i]);
i--;
}
if(i>=0 && p[i]==mq){
m[p[i]]++;
s.push(p[i]);
i--;
}
while(!s.empty()){
ans.push_back(s.top());
s.pop();
}
}
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
return 0;
}