221 子序列AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)For a sequence $X = (X_1, \dots, X_n)$ of positive integers, we call $X$ a 221 sequence if and only if the length and value are equal for every (length, value) pair in its run-length encoding. More formally, a sequence satisfying the following condition is called a 221 sequence.
对于一个正整数序列 $X = (X_1, \dots, X_n)$,当且仅当其游程编码中每个(长度,值)二元组的长度和值相等时,我们称 $X$ 为 221 序列。更形式化地说,满足以下条件的序列称为 221 序列。AI (CI翻译)
- For any integer pair
$(l, r)$satisfying$1 \leq l \leq r \leq n$, if all three of the following conditions hold, then$(r-l+1) = X_l$. $l = 1$or ($l \geq 2$and$X_{l-1} \neq X_l$)$r = n$or ($r \leq n-1$and$X_{r+1} \neq X_r$)$X_l = X_{l+1} = \dots = X_r$
- 对于任意满足
$1 \leq l \leq r \leq n$的整数二元组$(l, r)$,如果以下三个条件全部成立,那么$(r-l+1) = X_l$。 $l = 1$或($l \geq 2$且$X_{l-1} \neq X_l$)$r = n$或($r \leq n-1$且$X_{r+1} \neq X_r$)$X_l = X_{l+1} = \dots = X_r$
For example, $(2,2,3,3,3,1,2,2)$ is a 221 sequence, but $(1,1)$ and $(4,4,1,4,4)$ are not 221 sequences.
例如,$(2,2,3,3,3,1,2,2)$ 是 221 序列,但 $(1,1)$ 和 $(4,4,1,4,4)$ 不是 221 序列。AI (CI翻译)
You are given a sequence $A = (A_1, \dots, A_N)$ of positive integers of length $N$. Find the number, modulo $998244353$, of non-empty (not necessarily contiguous) subsequences of $A$ that are 221 sequences. Even if two subsequences are extracted from different positions, they are counted as one if they are equal as sequences.
给定一个长度为 $N$ 的序列 $A = (A_1, \dots, A_N)$。请求出 $A$ 的所有非空(不一定连续)子序列中,属于 221 序列的子序列数量,并将答案对 $998244353$ 取模。即使两个子序列是从不同位置提取出来的,只要它们作为序列相等,就只计数一次。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq N \leq 500\,000$$1 \leq A_i \leq N$- All input values are integers.
$1 \leq N \leq 500\,000$$1 \leq A_i \leq N$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N
A_1 A_2 \cdots A_N
N
A_1 A_2 \cdots A_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer on one line.
在一行中输出答案。AI (CI翻译)
样例
8
2 1 2 1 1 2 7 2
5
5
2 3 4 5 4
0
20
2 2 3 1 1 4 1 4 1 4 2 4 1 2 1 4 4 1 1 4
15
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。