专栏文章
题解:AT_arc205_e [ARC205E] Subset Product Problem
AT_arc205_e题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @minyvxvi
- 此快照首次捕获于
- 2025/12/02 10:36 3 个月前
- 此快照最后确认于
- 2025/12/02 10:36 3 个月前
AT_arc205_e [ARC205E] Subset Product Problem
如果没有 的限制就是 FWT 板子。发现如果你对于当前 暴力枚举子集或对于 暴力枚举超集都是不行的,但是发现可以平衡一下。具体的,设 表示前 位是 ,后 位是 的子集。每次更新或询问都是 的。
CPP#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;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...