当前位置: 移动技术网 > 移动技术>移动开发>Android > HDU6186 CS Course

HDU6186 CS Course

2020年07月08日  | 移动技术网移动技术  | 我要评论

思路:
一开始很SB的一直在想位运算,后来看了一下别人怎么写的,才发现这就是个前缀和后缀和垃圾题
P.S.卡多组输入

代码附:

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+10;
int a[N],XOR;
int andP[N],orP[N];
int andS[N],orS[N];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q,x;
    while(cin>>n>>q)
    {
        andP[0]=andS[n+1]=(1<<32)-1;
        orP[0]=orS[n+1]=0;
        XOR=0;
        for(int i=1; i<=n; ++i)
        {
            cin>>a[i];
            andP[i]=andP[i-1]&a[i];
            orP[i]=orP[i-1]|a[i];
            XOR^=a[i];
        }
        for(int i=n; i; --i)
        {
            andS[i]=andS[i+1]&a[i];
            orS[i]=orS[i+1]|a[i];
        }
        while(q--)
        {
            cin>>x;
            cout<<(andP[x-1]&andS[x+1])<<" "<<(orP[x-1]|orS[x+1])<<" "<<(XOR^a[x])<<endl;
        }
    }
    return 0;
}

本文地址:https://blog.csdn.net/qq_43586463/article/details/107176952

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网