-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathB_Card_Deck.cpp
More file actions
151 lines (127 loc) · 3.47 KB
/
B_Card_Deck.cpp
File metadata and controls
151 lines (127 loc) · 3.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define TC(t) while (t--)
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}
ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
bool primes[1000001]={true};
int N=1000000;
void sieve(){
FOR(i,0,N){
if(primes[i]==true){
for(int j=i*i;j<=N;j+=i)primes[i]=false;
}
}
}
/* int finMAXid(unordered_set<int>s,int key){
FOREACH(i,b)
}
void solve(){
int n;cin>>n;
unordered_set<int>s;
vector<int>arr(n);
FOR(i,0,n){int t;cin>>t;s.insert(t);}
vector<int>res;
while(arr.size()!=0){
}
}
*/
void solve(){
// cout<<999999999<<endl;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
priority_queue<pair<int,int>> q;
for(int i=0;i<n-1;i++)
{
if(i==0)
{
q.push({a[i],0});
}
else if (a[i]<a[i+1])
{
q.push({a[i+1],i+1});
}
}
vector<int> v;
for(int i=n-1;i>=0;i--) v.push_back(a[i]);
vector<int> temp;
vector<int> ans;
for(int i=n-1;i>=0;)
{
if(v.size()==0) break;
while(q.top().first!=a[i])
{
cout<<"inside:: "<<q.top().first<<endl;
int res = v.front();
cout<<"back " <<res<<endl;
// v.pop_front();
v.erase(v.begin());
// ans.push_back(res);
temp.push_back(res);
// if(i==0) break;
i--;
}
cout<<"outside:: "<<q.top().first<<endl;
int res = v.front();
cout<<res<<" i="<<i<<endl;
// v.pop_back();
v.erase(v.begin());
// ans.push_back(res);
temp.push_back(res);
reverse(temp.begin(),temp.end());
for(auto x:temp)
{
ans.push_back(x);
}
temp.erase(temp.begin(),temp.end());
q.pop();
if(i==0) break;
i--;
}
for(auto x:ans)
{
cout<<x<<" ";
}
cout<<endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
TC(t){
solve();
}
}