hdu 6186
题意:给出一个数列,q个询问,每个询问给出个下标,问除了该下标的数字,其他数字的and,or,xor是多少
思路:求个前缀,后缀即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 int a[N],b[N],c[N]; 7 int a1[N],b1[N],c1[N]; 8 int d[N]; 9 10 int main(){ 11 int n,m; 12 while(scanf("%d%d",&n,&m)!=EOF){ 13 // a[0]=b[0]=c[0]=0; 14 // a1[n+1]=b1[n+1]=c1[n+1]=0; 15 for(int i=1;i<=n;i++){ 16 scanf("%d",&d[i]); 17 if(i==1) { 18 a[i]=b[i]=c[i]=d[i];continue; 19 } 20 a[i]=d[i]&a[i-1]; 21 b[i]=d[i]|b[i-1]; 22 c[i]=d[i]^c[i-1]; 23 } 24 for(int i=n;i>=1;i--){ 25 if(i==n) { 26 a1[i]=b1[i]=c1[i]=d[i];continue; 27 } 28 a1[i]=d[i]&a1[i+1]; 29 b1[i]=d[i]|b1[i+1]; 30 c1[i]=d[i]^c1[i+1]; 31 } 32 int x; 33 for(int i=1;i<=m;i++){ 34 scanf("%d",&x); 35 if(x==1){ 36 printf("%d %d %d\n",a1[x+1],b1[x+1],c1[x+1]);continue; 37 } 38 if(x==n){ 39 printf("%d %d %d\n",a[x-1],b[x-1],c[x-1]);continue; 40 } 41 printf("%d ",a[x-1]&a1[x+1]); 42 printf("%d ",b[x-1]|b1[x+1]); 43 printf("%d",c[x-1]^c1[x+1]); 44 printf("\n"); 45 } 46 47 } 48 }