CF1876D.Lexichromatography

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aa consisting of nn elements, element ii has a value of aia_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 aa does not have any subarray that is imbalanced. A subarray is imbalanced if and only if there is a value kk such that the absolute difference between the number of blue elements with value kk and the number of red elements with value kk in this subarray is 22 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 353998\,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 pp and qq be two different sequences. Sequence pp is said to be lexicographically less than sequence qq if and only if pp is a prefix of qq or there is an index ii such that pj=qjp_j=q_j holds for every 1≤j<i1\leq j \lt i, and pi<qip_i \lt q_i. In particular, an empty sequence is always lexicographically less than any non-empty sequence.

帕克·查内克热爱他的学院——印度尼西亚大学计算机科学学院(Fasilkom)。他想玩转学院标志的两种颜色:蓝色与红色。

给定一个由 nn 个元素组成的数组 aa,其中第 ii 个元素的值为 aia_i。帕克·查内克希望将数组中每个元素染成蓝色或红色,使得以下条件全部满足:

  • 若将所有蓝色元素按其在原数组中的相对顺序提取出来构成一个子序列†^\dagger,红色元素同理也构成一个子序列,则蓝色子序列在字典序上严格小于红色子序列‡^\ddagger。
  • 数组 aa 的任意子数组均不能是“不平衡的”。一个子数组被称为不平衡的,当且仅当存在某个值 kk,使得该子数组中值为 kk 的蓝色元素个数与值为 kk 的红色元素个数之差的绝对值大于等于 22。
  • 注意:允许将数组中所有元素染成同一种颜色。

有多少种不同的染色方案满足上述所有条件?由于答案可能非常大,请输出答案对 998 244 353998\,244\,353 取模的结果。两种染色方案不同,当且仅当存在至少一个元素,在一种方案中被染为蓝色,而在另一种方案中被染为红色。

†^\dagger 数组的一个子序列是指通过删除原数组中若干(可能为零)个元素(不改变剩余元素的相对顺序)所得到的序列。

‡^\ddagger 设 pp 和 qq 是两个不同的序列。称序列 pp 在字典序上严格小于序列 qq,当且仅当 pp 是 qq 的前缀,或者存在某个下标 ii,使得对所有 1≤j<i1 \leq j < i 均有 pj=qjp_j = q_j,且 pi<qip_i < q_i。特别地,空序列在字典序上恒小于任何非空序列。

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \leq n \leq 2\cdot10^5) — the size of array aa.

The second line contains nn integers a1,a2,a3,…,ana_1,a_2,a_3,\ldots,a_n (1≤ai≤2⋅1051\leq a_i\leq2\cdot10^5).

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2\cdot10^5)—— 数组 aa 的大小。

第二行包含 nn 个整数 a1,a2,a3,…,ana_1,a_2,a_3,\ldots,a_n(1≤ai≤2⋅1051\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 353998\,244\,353.

一个整数,表示满足题目所有条件的不同染色方案数对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    8
    1 3 1 2 3 2 3 3

    输出#1

    3
  • 输入#2

    1
    265

    输出#2

    1

说明/提示

In the first example, the 33 ways for colouring all elements from index 11 to index 88 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 11 to index 88 to be red, red, blue, red, red, blue, blue, blue, it is not valid colouring, because for subarray a[2..6]a[2..6], there are 00 blue elements with value 33 and 22 red elements with value 33, making subarray a[2..6]a[2..6] an imbalanced subarray.

在第一个例子中,对索引 11 到索引 88 的所有元素进行染色的 33 种方式为:

  • 蓝、红、红、蓝、蓝、红、红、蓝。
  • 蓝、红、红、红、蓝、蓝、红、蓝。
  • 红、红、蓝、蓝、蓝、红、红、蓝。

例如,若将索引 11 到索引 88 的元素染成红、红、蓝、红、红、蓝、蓝、蓝,则该染色方案不合法,因为对于子数组 a[2..6]a[2..6],其蓝色元素个数为 00(对应值为 33),红色元素个数为 22(对应值为 33),导致子数组 a[2..6]a[2..6] 成为一个不平衡子数组。

输入解题思路,AI测评打分。不知道怎么写?

首页