309735: CF1726G. A Certain Magical Party

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

Description

A Certain Magical Party

题目描述

There are $ n $ people at a party. The $ i $ -th person has an amount of happiness $ a_i $ . Every person has a certain kind of personality which can be represented as a binary integer $ b $ . If $ b = 0 $ , it means the happiness of the person will increase if he tells the story to someone strictly less happy than them. If $ b = 1 $ , it means the happiness of the person will increase if he tells the story to someone strictly more happy than them. Let us define a speaking order as an ordering of the people from left to right. Now the following process occurs. We go from left to right. The current person tells the story to all people other than himself. Note that all happiness values stay constant while this happens. After the person is done, he counts the number of people who currently have strictly less/more happiness than him as per his kind of personality, and his happiness increases by that value. Note that only the current person's happiness value increases. As the organizer of the party, you don't want anyone to leave sad. Therefore, you want to count the number of speaking orders such that at the end of the process all $ n $ people have equal happiness. Two speaking orders are considered different if there exists at least one person who does not have the same position in the two speaking orders.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1 \leq n \leq 2 \cdot 10^5 $ ) — the number of people. The second line contains a sequence of $ n $ integers $ a_1,a_2,...,a_n $ ( $ 1 \leq a_i \leq 2n $ ) — the happiness values. The third line contains a sequence of $ n $ binary numbers $ b_1,b_2,...,b_n $ ( $ b_i \in \{0,1\} $ ) — the kinds of personality.

输出格式


Output the number of different valid speaking orders. Since this number can be large, output it modulo $ 998244353 $ .

输入输出样例

输入样例 #1

4
1 2 4 4
1 1 0 0

输出样例 #1

2

输入样例 #2

4
3 4 3 1
0 1 0 0

输出样例 #2

0

输入样例 #3

21
1 2 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 21 21
1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

输出样例 #3

49439766

说明

Here is the explanation for the first example. One valid speaking order is $ [2,1,4,3] $ (here, we have written the indices of each person). Each step shows the current happiness values and results. Step $ 1 $ : $ [1,2,4,4] $ $ \rightarrow $ Person $ 2 $ tells the story to others. Since his kind of personality is $ 1 $ , his happiness increases by $ 2 $ since persons $ 3 $ and $ 4 $ have strictly greater happiness. Step $ 2 $ : $ [1,4,4,4] $ $ \rightarrow $ Person $ 1 $ tells the story to others. Since his kind of personality is $ 1 $ , his happiness increases by $ 3 $ since persons $ 2 $ , $ 3 $ and $ 4 $ have strictly greater happiness. Step $ 3 $ : $ [4,4,4,4] $ $ \rightarrow $ Person $ 4 $ tells the story to others. Since his kind of personality is $ 0 $ , his happiness increases by $ 0 $ since no one has strictly lesser happiness. Step $ 4 $ : $ [4,4,4,4] $ $ \rightarrow $ Person $ 3 $ tells the story to others. Since his kind of personality is $ 0 $ , his happiness increases by $ 0 $ since no one has strictly lesser happiness. At the end, everyone has equal happiness. Note that $ [2,1,3,4] $ is also a valid answer for this example. It can be shown that there is no valid ordering for the second example.

Input

题意翻译

## 题意翻译 ### 题目描述 聚会上有 $n$ 个人,第 $i$ 个人有一个开心指数 $a_i$ 。 每个人都有一种确定的个性,这种个性可以用一个二进制整数 $b$ 来表示。如果 $b=0$ ,那么意味着如果他将一个故事讲给一个开心指数比他低的人,他的开心指数就会增加。如果 $b=1$ ,那么意味着如果他将一个故事讲给一个开心指数比他高的人,他的开心指数就会增加。 让我们定义讲故事的顺序为从左到右。接下来发生以下过程:从左至右的每个人给除他以外的所有人听。请注意,当这发生时,**所有的快乐指数保持不变**。当这个人讲完以后,他会根据他的个性计算目前开心指数比他少/多的人数,他的开心指数会加上这个量。请注意,**只有当前的人的快乐指数增加**。 作为聚会的组织者,你不希望任何人伤心地离开。因此,你需要计算可以使得全部 $n$ 人在这个过程的最后开心指数都相同的发言顺序的数量。如果两个发言顺序中至少有一个人的位置不同,则这两个发言顺序是不同的。 ### 输入格式 第一行为一个正整数 $n (1 \leq n \leq 2\times10^5)$ ,代表了人数。 第二行为 $n$ 个正整数 $a_1 , a_2 ,...,a_n(1\leq a_i\leq 2n)$ ,代表了每个人的开心指数。 第三行为 $n$ 个二进制整数 $b_1 , b_2 ,...,b_n(b_i \in \{0,1\})$ ,代表了每个人的个性。 ### 输出格式 输出不同发言顺序的总个数由于这个数字可能很大,所以请将它模 $998244353$ 输出。

Output

**题目大意:**

在一次聚会中有 $ n $ 个人,第 $ i $ 个人的初始幸福值为 $ a_i $。每个人的性格可以用二进制整数 $ b $ 表示,其中 $ b = 0 $ 表示如果这个人给比他幸福值严格小的人讲故事,他的幸福值会增加;$ b = 1 $ 表示如果这个人给比他幸福值严格大的人讲故事,他的幸福值会增加。

定义一个讲话顺序为从左到右排列的人的顺序。按照以下过程进行:从左到右,当前的人给除了他自己以外的所有人讲故事。注意在这个过程中所有幸福值保持不变。当这个人讲完后,他根据他的性格类型计算目前有多少人的幸福值比他严格小/大,他的幸福值就增加多少。注意只有当前人的幸福值会增加。

作为聚会组织者,你不想让任何人悲伤地离开。因此,你要计算有多少种讲话顺序,使得最后所有 $ n $ 个人的幸福值相等。

如果存在至少一个人在两个讲话顺序中位置不同,那么这两个讲话顺序被认为是不同的。

**输入输出数据格式:**

**输入格式:**
- 第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)——人数。
- 第二行包含 $ n $ 个整数 $ a_1, a_2, ..., a_n $($ 1 \leq a_i \leq 2n $)——幸福值序列。
- 第三行包含 $ n $ 个二进制数 $ b_1, b_2, ..., b_n $($ b_i \in \{0, 1\} $)——性格类型序列。

**输出格式:**
- 输出一个整数,表示不同的有效讲话顺序的数量,模 $ 998244353 $ 后的结果。

**输入输出样例:**

**输入样例 #1:**
```
4
1 2 4 4
1 1 0 0
```
**输出样例 #1:**
```
2
```

**输入样例 #2:**
```
4
3 4 3 1
0 1 0 0
```
**输出样例 #2:**
```
0
```

**输入样例 #3:**
```
21
1 2 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 21 21
1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
```
**输出样例 #3:**
```
49439766
```**题目大意:** 在一次聚会中有 $ n $ 个人,第 $ i $ 个人的初始幸福值为 $ a_i $。每个人的性格可以用二进制整数 $ b $ 表示,其中 $ b = 0 $ 表示如果这个人给比他幸福值严格小的人讲故事,他的幸福值会增加;$ b = 1 $ 表示如果这个人给比他幸福值严格大的人讲故事,他的幸福值会增加。 定义一个讲话顺序为从左到右排列的人的顺序。按照以下过程进行:从左到右,当前的人给除了他自己以外的所有人讲故事。注意在这个过程中所有幸福值保持不变。当这个人讲完后,他根据他的性格类型计算目前有多少人的幸福值比他严格小/大,他的幸福值就增加多少。注意只有当前人的幸福值会增加。 作为聚会组织者,你不想让任何人悲伤地离开。因此,你要计算有多少种讲话顺序,使得最后所有 $ n $ 个人的幸福值相等。 如果存在至少一个人在两个讲话顺序中位置不同,那么这两个讲话顺序被认为是不同的。 **输入输出数据格式:** **输入格式:** - 第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)——人数。 - 第二行包含 $ n $ 个整数 $ a_1, a_2, ..., a_n $($ 1 \leq a_i \leq 2n $)——幸福值序列。 - 第三行包含 $ n $ 个二进制数 $ b_1, b_2, ..., b_n $($ b_i \in \{0, 1\} $)——性格类型序列。 **输出格式:** - 输出一个整数,表示不同的有效讲话顺序的数量,模 $ 998244353 $ 后的结果。 **输入输出样例:** **输入样例 #1:** ``` 4 1 2 4 4 1 1 0 0 ``` **输出样例 #1:** ``` 2 ``` **输入样例 #2:** ``` 4 3 4 3 1 0 1 0 0 ``` **输出样例 #2:** ``` 0 ``` **输入样例 #3:** ``` 21 1 2 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 21 21 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 ``` **输出样例 #3:** ``` 49439766 ```

加入题单

上一题 下一题 算法标签: