A16209 | Lexichromatography
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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$ ).
The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ( $1\leq a_i\leq2\cdot10^5$ ).
输出格式
An integer representing the number of different colourings that satisfy all of the problem's conditions, modulo $998\,244\,353$ .
输入输出样例
输入 #1
8 1 3 1 2 3 2 3 3
输出 #1
3
输入 #2
1 265
输出 #2
1
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.
- 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted