{"problem":{"name":"E. 只有一端开口的瓶子","description":{"content":"_栈就是像 \"只有一端开口的瓶子\" 一样的数据结构，大家可以理解为一个头部固定的数组，无论是取出数字还是放入数字，你都只能在数组末尾那一端（称为栈顶）修改。_ 非常喜欢数据结构的周老师又在给新加入 ACM 俱乐部的小萌新们传授他的人生经验...... 这天，周老师得到了一个乱序的全排列，其中 $1 \\\\\\\\cdots n$ 共 $n$ 个数字，每个数字都恰好只出现一次。但是周老师不喜欢无序的东","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10217E"},"statements":[{"statement_type":"Markdown","content":"_栈就是像 \"只有一端开口的瓶子\" 一样的数据结构，大家可以理解为一个头部固定的数组，无论是取出数字还是放入数字，你都只能在数组末尾那一端（称为栈顶）修改。_\n\n非常喜欢数据结构的周老师又在给新加入 ACM 俱乐部的小萌新们传授他的人生经验......\n\n这天，周老师得到了一个乱序的全排列，其中 $1 \\\\\\\\cdots n$ 共 $n$ 个数字，每个数字都恰好只出现一次。但是周老师不喜欢无序的东西，所以他总想要把这个数列弄成一个递增的新数列。但是他现在手里恰好只有一些简单的数据结构—— $k$ 个栈。这些栈一开始全都为空，周老师想要只通过 $3$ 种操作，把初始的序列变成有序的新序列：\n\n周老师非常的睿智，他一下就想到了如果持有的栈的个数大等于数字总个数（也就是 $k >= n$），那么一定可以完成这项排序工作。作为本次数据结构专题讲课的作业题，周老师想考考身为小萌新的你，至少需要多少个这样的栈才能把给定的初始序列变成有序的新序列呢？换句话说，周老师想知道 $k$ 的最小值 $texttt(m i n) {k}$ 是多少。\n\n第一行输入一个正整数 $T \" \"(1 <= T <= 100)$，表示数据组数。接下来 $T$ 组数据，每组数据均满足：\n\n对于每组数据，请输出一个正整数 $k$，表示至少需要 $k$ 个这样的栈才能把给定的初始序列变成有序的新序列。\n\n对于第一组数据，一种有效的方法是依次执行如下操作，即可只使用一个简单栈便处理完： \n\n对于第二组数据，一种有效的方法是依次执行如下操作，即可只使用一个简单栈便处理完： \n\n对于第三组数据，显然一个栈无法处理，至少需要两个栈来处理。\n\n## Input\n\n第一行输入一个正整数 $T \" \"(1 <= T <= 100)$，表示数据组数。接下来 $T$ 组数据，每组数据均满足：  第一行输入一个正整数 $n \" \"(1 <= n <= 10^5)$，表示本组数据输入的全排列序列长度。  第二行输入 $n$ 个由空格间隔开的正整数 $p_1, p_2, \\\\\\\\cdots, p_n$，描述全排列序列 $P$ 的组成元素。请注意该序列是有顺序的，操作 $1$ 只能从前往后取数字。输入保证 $[ 1, n ]$ 中每个正整数在 $p_1 \\\\\\\\cdots \" \"p_n$ 中恰好只出现一次。\n\n## Output\n\n对于每组数据，请输出一个正整数 $k$，表示至少需要 $k$ 个这样的栈才能把给定的初始序列变成有序的新序列。\n\n[samples]\n\n## Note\n\n对于第一组数据，一种有效的方法是依次执行如下操作，即可只使用一个简单栈便处理完：   _push 1_  _push 1_  _push 1_  _pop 1_  _pop 1_  _pop 1_ 对于第二组数据，一种有效的方法是依次执行如下操作，即可只使用一个简单栈便处理完：   _push 1_  _pop 1_  _push 1_  _pop 1_ 对于第三组数据，显然一个栈无法处理，至少需要两个栈来处理。","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z}^+ $ be the number of test cases.  \nFor each test case, let $ n \\in \\mathbb{Z}^+ $ be the length of a permutation $ \\pi = (\\pi_1, \\pi_2, \\dots, \\pi_n) $ of $ \\{1, 2, \\dots, n\\} $.  \n\n**Constraints**  \n1. $ 1 \\le T \\le 100 $  \n2. $ 1 \\le n \\le 100 $  \n3. $ \\pi $ is a permutation of $ \\{1, 2, \\dots, n\\} $  \n\n**Objective**  \nFind the minimum number $ k $ of stacks required to sort $ \\pi $ into increasing order $ (1, 2, \\dots, n) $ using only the following operations:  \n- Push the next element from the input to the top of any stack.  \n- Pop the top element from any stack to the output.  \n- Output elements must appear in strictly increasing order.  \n\n**Answer**  \n$ k = \\text{the size of the minimum number of decreasing subsequences needed to partition } \\pi $,  \nwhich equals the length of the **longest increasing subsequence** of $ \\pi $.  \n\nEquivalently, by Dilworth’s theorem:  \n$$\nk = \\text{length of the longest decreasing subsequence of } \\pi\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10217E","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}