Counting Events
Time limit2sMemory limit1024 MB
Given n numbers and q queries, decide for each query whether it can be built from the numbers by repeatedly applying bitwise OR and AND.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Statement
While waiting for Thanos on Titan, Doctor Strange did not waste time. He used the Eye of Agamotto, which holds the Time Stone, the fifth Infinity Stone, to calculate the odds of winning the war. He picked actions the Avengers can take and actions whose feasibility he needs to check. Each action is labeled with a number that uniquely identifies it. The Avengers' actions are , and the actions to check are .
The magician knows that the timeline works as follows. If action and action can be performed, then actions and can also be performed, where and are bitwise OR and bitwise AND. For each , decide whether it can be obtained this way. Help Strange, since Thanos will arrive on Titan soon. Any action can be performed any number of times.
Input
The first line contains , the number of actions the Avengers can perform ().
The next line contains integers , the numbers describing these actions (). All numbers are pairwise distinct.
The third line contains , the number of actions to check ().
The last line contains integers , the numbers describing these actions ().
Output
On the -th line, print YES if the action described by can be performed, and NO otherwise.
Hint
The numbers , , and can be obtained without using and , and .