2021牛客暑期多校训练营8-D-OR

为什么人均都会只有我卡一下午????????

这道题应该先处理出两个序列,一个是a[j],ap[j-1]的与序列,一个是或序列,然后枚举每一位是否可以为0或1,累乘入答案即可。注意当与和或都为1时,确定这意味必须是1,与和或都为0时,必为0。

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
const int mod = 1e9+7;
int a[N];
int b[N];
int f[N][2];
void solve()
{
    
    
    int n;
    cin >> n;
    for (int i = 1; i <= n-1; ++i) {
    
    
        cin >> a[i];
    }
    for (int i = 1; i <= n-1; ++i) {
    
    
        cin >> b[i];
        b[i] -= a[i];
    }
    int ans = 1;
    for (int i = 0; i < 31; ++i) {
    
    
        memset(f,0,sizeof f);
        f[1][0] = f[1][1] = 1;
        for (int j = 2; j <= n; ++j) {
    
    
            if (((a[j-1]>>i)&1)==1&&((b[j-1]>>i)&1)==1) f[j][1]+=f[j-1][1],f[j][0] = 0;
            else if (((a[j-1]>>i)&1)==1&&((b[j-1]>>i)&1)==0) f[j][1] += f[j-1][0],f[j][0] += f[j-1][1];
            else if (((a[j-1]>>i)&1)==0&&((b[j-1]>>i)&1)==0) f[j][0] += f[j-1][0],f[j][1] = 0;
        }
        ans = ans * (f[n][1] + f[n][0]);
    }
    cout << ans << endl;
}

signed main()
{
    
    
//    freopen("in.txt","r",stdin);
    solve();
}

猜你喜欢

转载自blog.csdn.net/weixin_45509601/article/details/119544820
今日推荐