#P3220. [HNOI2012] 与非

    ID: 2269 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2012并查集湖南位运算,按位构造

[HNOI2012] 与非

Description

NAND is a binary logical operation whose result is true if and only if the two input Boolean values are not both true. The truth table of the NAND operation is as follows (1 denotes true, 0 denotes false):

The NAND of two non-negative integers means writing them in binary and then applying the NAND operation bitwise on corresponding binary digits. Since the lengths of the two binary numbers may differ, we generally fix a most significant bit limit KK so that the binary representations of both numbers do not exceed KK bits; numbers shorter than KK bits are padded with leading zeros on the left.

Given NN non-negative integers A1,A2,,ANA_1, A_2, \ldots, A_N and the designated bit-length KK, using NAND operations and parentheses, where each number may be used any number of times, please determine how many numbers in the range [L,R][L, R] can be obtained.

Input Format

The first line contains four positive integers NN, KK, LL, and RR separated by spaces.
The second line contains NN non-negative integers A1,A2,,ANA_1, A_2, \ldots, A_N, as described above.

Constraints: K60K \le 60 and N1000N \le 1000, 0Ai2K10 \le A_i \le 2^K - 1, 0LR10180 \le L \le R \le 10^{18}.

Output Format

Output a single integer, the number of values in [L,R][L, R] that can be computed.

3  3 1 4
3  4 5
4

Hint

In Sample 1, $(3 \text{ NAND } 4) \text{ NAND } (3 \text{ NAND } 5) = 1$, 5 NAND 5=25 \text{ NAND } 5 = 2, and 33 and 44 can be obtained directly.

Translated by ChatGPT 5