题解:AT_arc205_e [ARC205E] Subset Product Problem
AT_arc205_e [ARC205E] Subset Product Problem
如果没有
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
using namespace std;
const int maxn = 5e6 + 5;
const int maxm = 2049;
const int mod = 998244353;
int n, a[maxn], B = (1 << 10) - 1, sum[maxm][maxm];
void insert(int x){
int y = x & B, w = x;
x >>= 10;
for(int s = B ^ y; ; s = (s - 1) & (B ^ y)){
sum[x][B ^ s] = 1ll * sum[x][B ^ s] * w % mod;
if(!s) break;
}
}
int query(int x){
int y = x & B, ans = 1;
x >>= 10;
for(int s = x; ; s = (s - 1) & x){
ans = 1ll * ans * sum[s][y] % mod;
if(!s) break;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i = 0; i < 1 << 10; i++) for(int j = 0; j < 1 << 10; j++) sum[j][i] = 1;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
insert(a[i]);
cout << query(a[i]) << '\n';
}
return 0;
}