201253: [AtCoder]ARC125 D - Unique Subsequence

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

Description

Score : $700$ points

Problem Statement

Given is a sequence of $N$ integers $A_1,A_2,\cdots,A_N$.

Find the number of non-empty subsequences $s$ of $A$ satisfying the following condition, modulo $998244353$.

  • There is only one way to extract $s$ from $A$. Formally, there uniquely exists a sequence of indices $1 \leq idx(1)<idx(2)<\cdots<idx(k) \leq N$ such that $A_{idx(i)}=s_i$ ($1 \leq i \leq k$), where $s=(s_1,s_2,\cdots,s_k)$.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i \leq N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

Print the answer.


Sample Input 1

3
1 2 1

Sample Output 1

5

The following five subsequences satisfy the condition.

  • $(1,1)$
  • $(1,2)$
  • $(1,2,1)$
  • $(2)$
  • $(2,1)$

The subsequence $(1)$ does not satisfy the condition since there are two ways to extract it.


Sample Input 2

4
4 2 1 3

Sample Output 2

15

Sample Input 3

12
1 2 3 6 9 2 3 3 9 6 1 6

Sample Output 3

1178

Input

题意翻译

给定长为 $n(n\le 2\times 10^5)$ 的数列 $a$,保证 $1\le a_i\le n$,求这个数列的非空、仅出现一次的子序列的个数 $\bmod 998244353$。 令构成子序列 $S$ 时选取的下标为 $s_1,\cdots,s_{k_1}$,构成子序列 $T$ 时所选取的下标为 $t_1,\cdots,t_{k_2}$,则在 $$\begin{cases}k_1=k_2\\\forall i\in[1,k_1],S_i=T_i\\\exists i\in[1,k_1],s_i\ne t_i\end{cases}$$ 时,认为 $S$ 在 $a$ 中出现了不止一次。

加入题单

上一题 下一题 算法标签: