#arc178f. F - Long Sequence Inversion
F - Long Sequence Inversion
Score : points
问题陈述
给定正整数 , 和 ,以及一个非负整数序列 。这里,满足 。
在输入中, 以二进制形式给出,而其他整数以十进制形式给出。
此外, 不是直接在输入中给出的。相反,对于每个 ,你将得到一个 整数序列 ,使得 。这里,满足 $0 \leq X_{i,0} < X_{i,1} < \cdots < X_{i,L_{i}-1} < N$。
找到序列 的逆序数,模 ,定义如下。
- 对于任何整数 使得 和任何整数 使得 ,以下成立:
- 等于 $\operatorname{popcount}(a \operatorname{AND} A_{b})$ 除以 的余数。
什么是 ?
整数 和 的按位 ,记作 ,定义如下:
- 在 的二进制表示中,()位上的数字是 当且仅当 和 的二进制表示中 位上的数字都是 ;否则是 。
例如,(二进制:)。一般来说, 个整数 的按位 定义为 $(\dots ((p_1 \operatorname{AND} p_2) \operatorname{AND} p_3) \operatorname{AND} \dots \operatorname{AND} p_k)$,可以证明这与 的顺序无关。
什么是 ?
对于非负整数 , 是 的二进制表示中 的数量。更准确地说,对于非负整数 使得 $\displaystyle x = \sum_{i=0}^{\infty} b_i 2^i\ (b_i \in {0, 1})$,满足 $\displaystyle \operatorname{popcount}(x) = \sum_{i=0}^{\infty} b_i$。例如, 是二进制中的 1101
,所以 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given positive integers , , and , and a sequence of non-negative integers . Here, holds.
In the input, is given as an -digit number in binary notation, while the other integers are given in decimal notation.
Additionally, is not given directly in the input. Instead, for each , you are given a sequence of integers such that . Here, $0 \leq X_{i,0} < X_{i,1} < \cdots < X_{i,L_{i}-1} < N$ holds.
Find the inversion number, modulo , of the sequence defined as follows.
- For any integer such that and any integer such that , the following holds:
- is equal to the remainder when $\operatorname{popcount}(a \operatorname{AND} A_{b})$ is divided by .
What is ?
The bitwise of integers and , denoted as , is defined as follows:
- In the binary representation of , the digit at the () place is if and only if the digits at the place in the binary representations of both and are ; otherwise, it is .
For example, (in binary: ). Generally, the bitwise of integers is defined as $(\dots ((p_1 \operatorname{AND} p_2) \operatorname{AND} p_3) \operatorname{AND} \dots \operatorname{AND} p_k)$, and it can be proved that this is independent of the order of .
What is ?
For a non-negative integer , is the number of s in the binary representation of . More precisely, for a non-negative integer such that $\displaystyle x = \sum_{i=0}^{\infty} b_i 2^i\ (b_i \in {0, 1})$, it holds that $\displaystyle \operatorname{popcount}(x) = \sum_{i=0}^{\infty} b_i$. For example, is 1101
in binary, so .
Constraints
- $0 \leq X_{i,0} < X_{i,1} < \cdots < X_{i,L_{i}-1} < N$
- All input values are integers.
- is given in binary notation.
- All numbers except are given in decimal notation.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 4
11
1 0
2 0 1
0
1 1
Sample Output 1
9
$A = (1, 3, 0, 2), B = (0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1)$.
Sample Input 2
3 3
101
2 1 2
2 0 1
1 0
Sample Output 2
23
$A = (6, 3, 1), B = (0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0)$.
Sample Input 3
16 7
1101010000100110
11 0 1 2 3 7 10 11 12 13 14 15
7 4 6 8 10 11 12 13
6 0 1 6 8 10 12
8 0 3 5 6 10 11 12 13
10 0 1 2 3 4 5 6 8 12 13
9 3 4 5 6 8 9 11 14 15
8 0 4 7 9 10 11 13 14
Sample Output 3
97754354
Sample Input 4
92 4
10101100101111111111011101111111101011001011111110011110111111101111111110100111100010111011
23 1 2 5 13 14 20 28 32 34 39 52 56 59 60 62 64 67 69 71 78 84 87 91
20 15 17 22 28 36 40 43 47 52 53 57 67 72 77 78 81 87 89 90 91
23 7 8 9 10 11 13 16 19 22 23 30 33 42 49 51 52 58 64 71 73 76 79 83
22 1 13 19 26 27 28 29 35 39 40 41 46 55 60 62 64 67 74 79 82 89 90
Sample Output 4
291412708
Find the number modulo .