310733: CF1877F. Lexichromatography

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Lexichromatographytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Pak Chanek loves his faculty, the Faculty of Computer Science, University of Indonesia (Fasilkom). He wants to play with the colours of the faculty's logo, blue and red.

There is an array $a$ consisting of $n$ elements, element $i$ has a value of $a_i$. Pak Chanek wants to colour each element in the array blue or red such that these following conditions are satisfied:

  • If all blue elements are formed into a subsequence$^\dagger$ and so are all the red elements, the blue subsequence is strictly less than the red subsequence lexicographically$^\ddagger$.
  • Array $a$ does not have any subarray that is imbalanced. A subarray is imbalanced if and only if there is a value $k$ such that the absolute difference between the number of blue elements with value $k$ and the number of red elements with value $k$ in this subarray is $2$ or more.
  • Note that it is possible to colour every element of the array the same colour.

How many different colourings satisfy all those conditions? Since the answer can be very big, print the answer modulo $998\,244\,353$. Two colourings are different if and only if there is at least one element that is blue in one colouring, but red in the other.

$^\dagger$ A subsequence of an array is a sequence that can be obtained from the array by deleting some elements (possibly none), without changing the order of the remaining elements.

$^\ddagger$ Let $p$ and $q$ be two different sequences. Sequence $p$ is said to be lexicographically less than sequence $q$ if and only if $p$ is a prefix of $q$ or there is an index $i$ such that $p_j=q_j$ holds for every $1\leq j<i$, and $p_i<q_i$. In particular, an empty sequence is always lexicographically less than any non-empty sequence.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 2\cdot10^5$) — the size of array $a$.

The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ($1\leq a_i\leq2\cdot10^5$).

Output

An integer representing the number of different colourings that satisfy all of the problem's conditions, modulo $998\,244\,353$.

ExamplesInput
8
1 3 1 2 3 2 3 3
Output
3
Input
1
265
Output
1
Note

In the first example, the $3$ ways for colouring all elements from index $1$ to index $8$ are:

  • Blue, red, red, blue, blue, red, red, blue.
  • Blue, red, red, red, blue, blue, red, blue.
  • Red, red, blue, blue, blue, red, red, blue.

As an example, if we colour the elements from index $1$ to index $8$ to be red, red, blue, red, red, blue, blue, blue, it is not valid colouring, because for subarray $a[2..6]$, there are $0$ blue elements with value $3$ and $2$ red elements with value $3$, making subarray $a[2..6]$ an imbalanced subarray.

Output

题目大意:
Pak Chanek 喜欢他的学院——印度尼西亚大学计算机科学学院(Fasilkom)的标志颜色,蓝色和红色。给定一个由 n 个元素组成的数组 a,元素 i 的值为 a_i。Pak Chanek 想要给数组的每个元素涂上蓝色或红色,使得满足以下条件:
1. 如果所有蓝色元素形成一个子序列,所有红色元素也形成一个子序列,那么蓝色子序列在字典序上严格小于红色子序列。
2. 数组 a 不包含任何不平衡的子数组。如果一个子数组中存在一个值 k,使得该子数组中蓝色元素和红色元素的数量之差的绝对值为 2 或更多,则该子数组是不平衡的。
3. 注意,可以给数组的每个元素涂上相同的颜色。

求满足所有条件的不同涂色方式的数量,结果对 998,244,353 取模。如果至少有一个元素在一个涂色方案中为蓝色而在另一个方案中为红色,则这两个方案是不同的。

输入输出数据格式:
输入:
- 第一行包含一个整数 n(1 ≤ n ≤ 2×10^5),表示数组 a 的大小。
- 第二行包含 n 个整数 a_1, a_2, a_3, …, a_n(1≤ a_i ≤ 2×10^5)。

输出:
- 一个整数,表示满足所有条件的不同涂色方式的数量,对 998,244,353 取模。

示例:
输入:
```
8
1 3 1 2 3 2 3 3
```
输出:
```
3
```

注意:
在第一个示例中,将索引 1 到索引 8 的元素涂色的 3 种方式是:
- 蓝色,红色,红色,蓝色,蓝色,红色,红色,蓝色
- 蓝色,红色,红色,红色,蓝色,蓝色,红色,蓝色
- 红色,红色,蓝色,蓝色,蓝色,红色,红色,蓝色
例如,如果我们将索引 1 到索引 8 的元素涂成红色,红色,蓝色,红色,红色,蓝色,蓝色,蓝色,这不是一个有效的涂色方案,因为对于子数组 a[2..6],值为 3 的蓝色元素有 0 个,红色元素有 2 个,使得子数组 a[2..6] 成为不平衡的子数组。题目大意: Pak Chanek 喜欢他的学院——印度尼西亚大学计算机科学学院(Fasilkom)的标志颜色,蓝色和红色。给定一个由 n 个元素组成的数组 a,元素 i 的值为 a_i。Pak Chanek 想要给数组的每个元素涂上蓝色或红色,使得满足以下条件: 1. 如果所有蓝色元素形成一个子序列,所有红色元素也形成一个子序列,那么蓝色子序列在字典序上严格小于红色子序列。 2. 数组 a 不包含任何不平衡的子数组。如果一个子数组中存在一个值 k,使得该子数组中蓝色元素和红色元素的数量之差的绝对值为 2 或更多,则该子数组是不平衡的。 3. 注意,可以给数组的每个元素涂上相同的颜色。 求满足所有条件的不同涂色方式的数量,结果对 998,244,353 取模。如果至少有一个元素在一个涂色方案中为蓝色而在另一个方案中为红色,则这两个方案是不同的。 输入输出数据格式: 输入: - 第一行包含一个整数 n(1 ≤ n ≤ 2×10^5),表示数组 a 的大小。 - 第二行包含 n 个整数 a_1, a_2, a_3, …, a_n(1≤ a_i ≤ 2×10^5)。 输出: - 一个整数,表示满足所有条件的不同涂色方式的数量,对 998,244,353 取模。 示例: 输入: ``` 8 1 3 1 2 3 2 3 3 ``` 输出: ``` 3 ``` 注意: 在第一个示例中,将索引 1 到索引 8 的元素涂色的 3 种方式是: - 蓝色,红色,红色,蓝色,蓝色,红色,红色,蓝色 - 蓝色,红色,红色,红色,蓝色,蓝色,红色,蓝色 - 红色,红色,蓝色,蓝色,蓝色,红色,红色,蓝色 例如,如果我们将索引 1 到索引 8 的元素涂成红色,红色,蓝色,红色,红色,蓝色,蓝色,蓝色,这不是一个有效的涂色方案,因为对于子数组 a[2..6],值为 3 的蓝色元素有 0 个,红色元素有 2 个,使得子数组 a[2..6] 成为不平衡的子数组。

加入题单

上一题 下一题 算法标签: