专栏文章

题解: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

如果没有 iki\le k 的限制就是 FWT 板子。发现如果你对于当前 aka_k 暴力枚举子集或对于 aia_i 暴力枚举超集都是不行的,但是发现可以平衡一下。具体的,设 sumx,ysum_{x,y} 表示前 1010 位是 xx,后 1010 位是 yy 的子集。每次更新或询问都是 O(210)O(2^{10}) 的。
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 条评论,欢迎与作者交流。

正在加载评论...