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