【題目敘述】http://codeforces.com/contest/1492/problem/B
#include <iostream>
using namespace std;
const int maxn = 100005;
int t, n, a[maxn], pre[maxn], mx;
int main() {
cin >> t;
while (t--){
cin >> n;
mx = 0;
for (int i = 1; i <= n; i++){
cin >> a[i];
if (a[i] > mx){
pre[i] = i;
mx = a[i];
}
else pre[i] = pre[i-1];
}
int r = n;
while (r){
int now = pre[r];
for (int i = now; i <= r; i++){
cout << a[i] << " ";
}
r = now-1;
}
cout << "\n";
}
}