Drop Min

AtCoder
IDarc212_e
Time2000ms
Memory256MB
Difficulty
There is a permutation $P$ of $(1,2,\ldots,N)$ and an empty array $A$. Perform the following operation $N-1$ times on $P$: * Choose two adjacent elements. Remove the smaller of the chosen elements from $P$ and concatenate the parts before and after the removed element. Append the removed element to the end of $A$. Find the number, modulo $998244353$, of possible final sequences $A$ of length $N-1$. ## Constraints * $2 \le N \le 2\times 10^5$ * $1 \le P_i \le N$ * $P$ is a permutation of $(1,2,\ldots,N)$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $P_1$ $P_2$ $\ldots$ $P_N$ [samples]
Samples
Input #1
4
1 2 3 4
Output #1
6

All six permutations of $(1,2,3)$ are possible as the final $A$.
For example, $A=(2,1,3)$ can be obtained as follows:

*   Choose $2,3$. Remove $2$, and now $P=(1,3,4), A=(2)$.
*   Choose $1,3$. Remove $1$, and now $P=(3,4), A=(2,1)$.
*   Choose $3,4$. Remove $3$, and now $P=(4), A=(2,1,3)$.
Input #2
3
3 1 2
Output #2
1
Input #3
24
10 24 3 4 8 14 5 2 22 9 21 1 15 6 13 23 18 12 7 17 19 16 20 11
Output #3
303178128
API Response (JSON)
{
  "problem": {
    "name": "Drop Min",
    "description": {
      "content": "There is a permutation $P$ of $(1,2,\\ldots,N)$ and an empty array $A$. Perform the following operation $N-1$ times on $P$: *   Choose two adjacent elements. Remove the smaller of the chosen elements ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc212_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a permutation $P$ of $(1,2,\\ldots,N)$ and an empty array $A$. Perform the following operation $N-1$ times on $P$:\n\n*   Choose two adjacent elements. Remove the smaller of the chosen elements ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments