問題一覧 > 通常問題

No.1031 Mischievous Big Sister

レベル : / AI推定難易度 : 2025 / 実行時間制限 : 1ケース 3.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 61
作問者 : Rho / テスター : Thistle
お気に入りにしたユーザー ProblemId : 4171 / 自分の提出
問題文最終更新日: 2020-05-29 20:26:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 244 (順位表) の他の問題:

Problem Statement

Shinobu has a permutation $p$ of length $N$.
One day, while Shinobu was taking a nap, Isami played a prank on this permutation. In the prank, the following operation was performed.

  • Choose an interval $[l,r]$ of length $2$ or more from the permutation ${p}$.
  • Choose the maximum element $p_{max}$ and the minimum element $p_{min}$ in the interval $[l,r]$, and swap their two positions.
To help Shinobu, who wants to restore the permutation, find the number of possible permutations after Isami's operation.

Input

$N$
$p_1\ p_2\ ... p_N$

All inputs are integers.
$1 \leq N \leq 10^5$
$1 \leq p_i \leq N (1 \leq i \leq N)$
$p_i ≠ p_j (i ≠ j)$

Output

Output the number of possible permutations after the operation.
Print a newline at the end.

Sample

Sample 1
Input
3
2 1 3
Output
2

If Isami chooses the interval $[1,2]$, the sequence after the operation is ${1,2,3}$.
If she chooses the interval $[1,3]$, the sequence after the operation is ${2,3,1}$.
If she chooses the interval $[2,3]$, the permutation after the operation is ${2,3,1}$.
Therefore, the answer to output is $2$.

Sample 2
Input
5
1 2 3 4 5
Output
10

Sample 3
Input
8
1 7 3 2 5 8 6 4
Output
11

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。