{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"你有一副$n$的扑克牌,你想把它重新排列成一副新的扑克牌。\n\n每张牌的$1$和$n$之间的数值都等于$p_i$。所有$p_i$都是成对不同的。一副牌从下往上编号,即$p_1$代表底牌,$p_n$是顶牌。\n\n每一步都选取一个整数$k \u0026gt; 0$,从原来的牌组中抽取最上面的$k$张牌,按照现在的顺序放在新牌组的上面。请参阅注释部分以加深理解)。\n\n让我们定义一副牌的顺序为 $\\sum\\limits_{i \u003d 1}^{n}{n^{n - i} \\cdot p_i}$。\n\n在给定原始牌组的情况下,输出使用上述操作可以得到的最大顺序的牌组。"}},{"title":"Input","value":{"format":"MD","content":"**输入**\n\n第一行包含一个整数 $t$($1 \\le t \\le 1000$)--测试用例数。\n\n每个测试用例的第一行包含一个整数 $n$ ($1 \\le n \\le 10^5$)--你所拥有的牌的大小。\n\n第二行包含 $n$个整数 $p_1, p_2,\\dots, p_n$($1 \\le p_i \\le n$;如果是$i \\neq j$,则为$p_i \\neq p_j$)--牌组中从下到上的牌的值。\n\n保证所有测试用例中的$n$之和不超过$10^5$。"}},{"title":"Output","value":{"format":"MD","content":"**输出**\n\n为每个测试用例打印最大可能顺序的牌面。从下到上打印牌面中的牌值。\n\n如果有多个答案,则打印其中任何一个。"}},{"title":"Sample 1","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"**注**\n\n在第一个测试案例中,最优策略之一是下一个策略:\n\n1. 从$p$上面取下$1$张牌,并将它移到$p\u0027$上 $p$变为$[1, 2, 3]$,$p\u0027$变为$[4]$;\n2. 从$p$上面取$1$张牌 $p$变成$[1, 2]$,$p\u0027$变成$[4, 3]$;\n3.从$p$上面取$1$张牌 $p$变为$[1]$,$p\u0027$变为$[4, 3, 2]$;\n4.从$p$上面取$1$张牌 $p$变为空牌,$p\u0027$变为$[4, 3, 2, 1]$。\n\n结果,$p\u0027$的阶等于$4^3 \\cdot 4 + 4^2 \\cdot 3 + 4^1 \\cdot 2 + 4^0 \\cdot 1 $\u003d$256 + 48 + 8 + 1 \u003d 313$.\n\n在第二个测试案例中,最优策略之一是\n\n1. 从$p$上面取$4$张牌,并把它移到$p\u0027$上 $p$变为$[1]$,$p\u0027$变为$[5, 2, 4, 3]$;\n2. 从$p$上面取$1$张牌,移到$p\u0027$上 $p$变为空牌,$p\u0027$变为$[5, 2, 4, 3, 1]$;\n\n因此,$p\u0027$的阶等于$5^4 \\cdot 5 + 5^3 \\cdot 2 + 5^2 \\cdot 4 + 5^1 \\cdot 3 + 5^0 \\cdot 1 $\u003d$3125 + 250 + 100 + 15 + 1 \u003d 3491$.\n\n在第三个测试案例中,最优策略之一是\n\n1. 从$p$上面取$2$张牌,并把它移到$p\u0027$上 $p$变为$[4, 2, 5, 3]$,$p\u0027$变为$[6, 1]$;\n2. 从$p$上面取$2$张牌,移到$p\u0027$上 $p$变成$[4, 2]$,$p\u0027$变成$[6, 1, 5, 3]$;\n3.从$p$上面取$2$张牌,移到$p\u0027$上 $p$变为空牌,$p\u0027$变为$[6, 1, 5, 3, 4, 2]$。\n\n结果,$p\u0027$的阶等于$6^5 \\cdot 6 + 6^4 \\cdot 1 + 6^3 \\cdot 5 + 6^2 \\cdot 3 + 6^1 \\cdot 4 + 6^0 \\cdot 2 $\u003d$46656 + 1296 + 1080 + 108 + 24 + 2 \u003d 49166$."}}]}