{"trustable":true,"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":"HTML","content":"\n\u003cp\u003e你有一副$$$n$$$张卡牌,你想要重新排列成一个新的牌组。\u003c/p\u003e\n\u003cp\u003e每张卡牌的值在$$$1$$$到$$$n$$$之间,记为$$$p_i$$$。所有的$$$p_i$$$两两不同。牌组中的卡牌从底部到顶部编号,即$$$p_1$$$表示底部的牌,$$$p_n$$$表示顶部的牌。\u003c/p\u003e\n\u003cp\u003e每一步,你选择一个大于$$$0$$$的整数$$$k$$$,从原始牌组中取出顶部的$$$k$$$张牌,并按照它们的顺序放在新的牌组的顶部。你重复这个操作,直到原始牌组为空。(详见注释部分以便更好理解)\u003c/p\u003e\n\u003cp\u003e我们定义一个牌组的\u003cspan class\u003d\"tex-font-style-it\"\u003e顺序\u003c/span\u003e为$$$\\sum\\limits_{i \u003d 1}^{n}{n^{n - i} \\cdot p_i}$$$。\u003c/p\u003e\n\u003cp\u003e给定原始牌组,请输出使用上述操作可以得到的顺序最大的牌组。\u003c/p\u003e\n"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含一个整数$$$t$$$($$$1 \\le t \\le 1000$$$)——测试用例的数量。\u003c/p\u003e\n\u003cp\u003e每个测试用例的第一行包含一个整数$$$n$$$($$$1 \\le n \\le 10^5$$$)——你拥有的牌组的大小。\u003c/p\u003e\n\u003cp\u003e第二行包含$$$n$$$个整数$$$p_1, p_2,\\dots, p_n$$$($$$1 \\le p_i \\le n$$$;$$$i \\neq j$$$时,$$$p_i \\neq p_j$$$)——牌组中卡牌的值,从底部到顶部。\u003c/p\u003e\n\u003cp\u003e保证所有测试用例中$$$n$$$的总和不超过$$$10^5$$$。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e对于每个测试用例,输出顺序最大的牌组。按照从底部到顶部的顺序输出牌组中的值。\u003c/p\u003e\n\u003cp\u003e如果有多个答案,可以输出任意一个。\u003c/p\u003e"}},{"title":"示例1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003e输入\u003c/th\u003e\n \u003cth\u003e输出\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"}},{"title":"注释","value":{"format":"HTML","content":"\u003cp\u003e在第一个测试用例中,一种最优策略如下:\u003c/p\u003e\n\u003col\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$1$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[1, 2, 3]$$$,$$$p\u0027$$$变为$$$[4]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$1$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[1, 2]$$$,$$$p\u0027$$$变为$$$[4, 3]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$1$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[1]$$$,$$$p\u0027$$$变为$$$[4, 3, 2]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$1$$$张牌放入$$$p\u0027$$$:$$$p$$$变为空,$$$p\u0027$$$变为$$$[4, 3, 2, 1]$$$。\u003c/li\u003e\n\u003c/ol\u003e 结果中,$$$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\u003cp\u003e在第二个测试用例中,一种最优策略如下:\u003c/p\u003e\n\u003col\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$4$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[1]$$$,$$$p\u0027$$$变为$$$[5, 2, 4, 3]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$1$$$张牌放入$$$p\u0027$$$:$$$p$$$变为空,$$$p\u0027$$$变为$$$[5, 2, 4, 3, 1]$$$。\u003c/li\u003e\n\u003c/ol\u003e 结果中,$$$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\u003cp\u003e在第三个测试用例中,一种最优策略如下:\u003c/p\u003e\n\u003col\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$2$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[4, 2, 5, 3]$$$,$$$p\u0027$$$变为$$$[6, 1]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$2$$$张牌放入$$$p\u0027$$$:$$$p$$$变为$$$[4, 2]$$$,$$$p\u0027$$$变为$$$[6, 1, 5, 3]$$$;\u003c/li\u003e\n \u003cli\u003e从$$$p$$$的顶部取出$$$2$$$张牌放入$$$p\u0027$$$:$$$p$$$变为空,$$$p\u0027$$$变为$$$[6, 1, 5, 3, 4, 2]$$$。\u003c/li\u003e\n\u003c/ol\u003e 结果中,$$$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$$$。"}}]}