正文
增加 19 行删除 19 行
123456789101113 行未改动25262728293031323334353637383940414243444546474849505152535475 行未改动130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160## [SOS Bit Problem](https://cses.fi/problemset/task/1654/)给定一个包含 $n$ 个整数的数组,你的任务是计算每个元素 $x$ 的:1. 有多少元素 $y$ 满足 $x∣y = x$2. 有多少元素 $y$ 满足 $x \& y = x$3. 有多少元素 $y$ 满足 $x \& y \neq 0$**限制:**- $1 \leqslant n \leqslant 2 \times 10^5$13 行未改动using namespace std;int main() {cin.tie(nullptr) -> sync_with_stdio(false);int n;cin >> n;vector<int> a(n);rep(i, n) cin >> a[i];int m = 20;int m2 = 1<<m;vector<int> cnt(m2);rep(i, n) cnt[a[i]]++;vector<int> f = cnt;rep(i, m)rep(j, m2) if (j>>i&1) f[j] += f[j^1<<i];vector<int> g = cnt;rep(i, m)rep(j, m2) if (j>>i&1) g[j^1<<i] += g[j];for (int x : a) {cout << f[x] << ' ' << g[x] << ' ' << n-f[~x&m2-1] << '\n';}return 0;}```75 行未改动}int main() {cin.tie(nullptr) -> sync_with_stdio(false);int n;cin >> n;vector<int> a(n);rep(i, n) cin >> a[i];int m = 18;int m2 = 1<<m;vector<int> d(m2);rep(i, n) d[a[i]]++;rep(i, m)rep(j, m2) if (j>>i&1) d[j^1<<i] += d[j];vector<mint> two(n+1, 1);rep(i, n) two[i+1] = two[i]*2;vector<mint> dp(m2);rep(i, m2) dp[i] = two[d[i]]-1;rep(i, m)rep(j, m2) if (j>>i&1) dp[j^1<<i] -= dp[j];rep(i, n+1) cout << dp[i] << " \n"[i == n];return 0;}```123456789101113 行未改动25262728293031323334353637383940414243444546474849505152535475 行未改动130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160## [SOS Bit Problem](https://cses.fi/problemset/task/1654/)给定一个包含 $n$ 个整数的数组,你的任务是计算每个元素 $x$ 的:1. 有多少元素 $y$ 满足 $x∣y = x$2. 有多少元素 $y$ 满足 $x \& y = x$3. 有多少元素 $y$ 满足 $x \& y \neq 0$**限制:**- $1 \leqslant n \leqslant 2 \times 10^5$13 行未改动using namespace std;int main() {cin.tie(nullptr) -> sync_with_stdio(false);int n;cin >> n;vector<int> a(n);rep(i, n) cin >> a[i];int m = 20;int m2 = 1<<m;vector<int> cnt(m2);rep(i, n) cnt[a[i]]++;vector<int> f = cnt;rep(i, m)rep(j, m2) if (j>>i&1) f[j] += f[j^1<<i];vector<int> g = cnt;rep(i, m)rep(j, m2) if (j>>i&1) g[j^1<<i] += g[j];for (int x : a) {cout << f[x] << ' ' << g[x] << ' ' << n-f[~x&m2-1] << '\n';}return 0;}```75 行未改动}int main() {cin.tie(nullptr) -> sync_with_stdio(false);int n;cin >> n;vector<int> a(n);rep(i, n) cin >> a[i];int m = 18;int m2 = 1<<m;vector<int> d(m2);rep(i, n) d[a[i]]++;rep(i, m)rep(j, m2) if (j>>i&1) d[j^1<<i] += d[j];vector<mint> two(n+1, 1);rep(i, n) two[i+1] = two[i]*2;vector<mint> dp(m2);rep(i, m2) dp[i] = two[d[i]]-1;rep(i, m)rep(j, m2) if (j>>i&1) dp[j^1<<i] -= dp[j];rep(i, n+1) cout << dp[i] << " \n"[i == n];return 0;}```