用一个bool数组表示每个数是否能被表示,初始化把Q所有元素设为1,然后跑一个高维前缀和算出所有的子集,类似多源最短路,这个过程可以同时多源进行

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 1e7 + 10, M = 2e6 + 10, inf = (1 &lt;&lt; 20) - 1;

inline int read() {
    bool sym = 0; int res = 0; char ch = getchar();
    while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) res = (res &lt;&lt; 3) + (res &lt;&lt; 1) + (ch ^ 48), ch = getchar();
    return sym ? -res : res;
}

int n, m, cnt, vis[N];

int main() {
    n = read(); m = read();
    for (int i = 1; i &lt;= n; i++) {int x = read(); vis[x] = 1;}
    for (int i = 0; i &lt; 20; i++) {
        for (int j = 0; j &lt;= inf; j++) {
            if (!(j &gt;&gt; i &amp; 1)) vis[j] |= vis[j | 1 &lt;&lt; i];
        }
    }
    for (int i = 1; i &lt;= m; i++) {
        int x = read(); printf(vis[x] ? "yes\n" : "no\n");
    }
    return 0;
}
```</queue></algorithm></cstring></cmath></cstdio></iostream>