#P7076. [CSP-S 2020] 动物园

    ID: 6124 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学贪心2020进制位运算,按位CSP S 提高级

[CSP-S 2020] 动物园

Description

The zoo keeps many animals. Zookeeper A will buy different types of feed according to the animals being kept, following the “Feeding Guide”, and will send the purchase list to buyer B.

Specifically, there are 2k2^k different kinds of animals in the animal world, numbered from 00 to 2k12^k - 1. The zoo keeps nn of them, and the ID of the ii-th animal is aia_i.

There are mm rules in the “Feeding Guide”. The jj-th rule is of the form: “If the zoo keeps some animal such that the pjp_j-th bit of its binary representation is 11, then it must buy the qjq_j-th type of feed.” There are cc types of feed in total, numbered from 11 to cc. In this problem, we treat an animal ID’s binary representation as a kk-bit 01 string: bit 00 is the lowest bit, and bit k1k - 1 is the highest bit.

According to the “Feeding Guide”, A will make a feed list and hand it to B, who will buy the feed. The list is a cc-bit 01 string: if the ii-th bit is 11, it means the ii-th type of feed needs to be bought; if the ii-th bit is 00, it means it does not need to be bought. In fact, based on the feed that has been bought, the zoo may be able to keep more animals. More specifically, if adding a currently unkept animal with ID xx to the zoo does not change the feed list, then we say that the zoo can currently also keep the animal with ID xx.

Now B wants you to help compute how many kinds of animals the zoo can still keep at the moment.

Input Format

The first line contains four integers n,m,c,kn, m, c, k separated by spaces.
They represent the number of animals currently kept in the zoo, the number of rules in the “Feeding Guide”, the number of feed types, and the number of bits in the binary representation of an animal ID.
The second line contains nn integers separated by spaces, where the ii-th integer is aia_i.
The next mm lines each contain two integers pi,qip_i, q_i, describing one rule.
The data guarantees that all aia_i are pairwise distinct, and all qiq_i are pairwise distinct.

Output Format

Output one integer in a single line, representing the answer.

3 3 5 4
1 4 6
0 3
2 4
2 5
13
2 2 4 3
1 2
1 3
2 4
2
见附件中的 zoo/zoo3.in
见附件中的 zoo/zoo3.ans

Hint

[Sample #1 Explanation]

The zoo keeps three kinds of animals with IDs 1,4,61, 4, 6. The “Feeding Guide” contains three rules:

  1. If some kept animal has the 00-th binary bit equal to 11, then feed type 33 must be bought.
  2. If some kept animal has the 22-th binary bit equal to 11, then feed type 44 must be bought.
  3. If some kept animal has the 22-th binary bit equal to 11, then feed type 55 must be bought.

The feed purchase situation is:

  1. The animal with ID 11 has the 00-th binary bit equal to 11, so feed type 33 needs to be bought.
  2. The animals with IDs 4,64, 6 have the 22-th binary bit equal to 11, so feed types 4,54, 5 need to be bought.

Since adding an animal with ID being one of 0,2,3,5,7,8,,150, 2, 3, 5, 7, 8, \ldots , 15 will not change the shopping list, the answer is 1313.

[Constraints]

For 20%20\% of the testdata, kn5k \le n \le 5, m10m \le 10, c10c \le 10, and all pip_i are pairwise distinct.
For 40%40\% of the testdata, n15n \le 15, k20k \le 20, m20m \le 20, c20c \le 20.
For 60%60\% of the testdata, n30n \le 30, k30k \le 30, m1000m \le 1000.
For 100%100\% of the testdata, 0n,m1060 \le n, m \le 10^6, 0k640 \le k \le 64, 1c1081 \le c \le 10^8.

Translated by ChatGPT 5