hdu6085[压位+暴力] 2017多校5

/*hdu6085[压位+暴力] 2017多校5*/
/*强行优化..*/
#include <bits/stdc++.h>
using namespace std;
struct bits{ unsigned num[2000]; unsigned bitlen; bits(){memset(num,0,sizeof(num)),bitlen=0;} bits get(int l, int r) { bits ret; int length=r-l+1; int left,len1,len2,pos=0; left=l/32; len1=(l%32); len2=32-len1; while(length>0){ if(len2==32) ret.num[pos++]=num[left]; else ret.num[pos++]=(num[left]>>len1)|(num[left+1]<<len2); left++; length-=32; } pos--; if(length<0){ ret.num[pos]<<=(-length); ret.num[pos]>>=(-length); } ret.bitlen=pos+1; return ret; } void add(int p) { int next=p/32; int move=p%32; num[next]|=(1<<move); } void show(int p){ int next=p/32; int move=p%32; printf("%d",(num[next]&(1<<move))?1:0); } }; void Xor(bits& a,bits& b){ for(int i=0;i<(int)b.bitlen;i++){ a.num[i]^=b.num[i]; } } int T,n,m,q,b[50005]; void solve(){ int temp,maxA=0; bits A,B,ans; scanf("%d%d%d",&n,&m,&q); for(int i=0;i<n;i++){ scanf("%d",&temp); A.add(temp); maxA=max(temp,maxA); } for(int i=0;i<m;i++){ scanf("%d",&temp); for(int k=0;;k++){ if(((k+1)*temp-1)>maxA){ B=A.get(k*temp,maxA); Xor(ans,B); break; } else B=A.get(k*temp,(k+1)*temp-1); Xor(ans,B); } } for(int i=0;i<q;i++){ scanf("%d",&temp); ans.show(temp); puts(""); } } int main() { scanf("%d",&T); while(T--) solve(); return 0; }

还有升级版本, 太强了.

#include <bits/stdc++.h>
using namespace std;
struct bits {
    unsigned n[10010];
    void set(unsigned x) {n[x >> 5] |= (1 << (x & 31));}
    void flip(int x) {n[x >> 5] ^= (1 << (x & 31));}
    bool get(int x) {return n[x >> 5] & (1 << (x & 31));}
    void clear() {memset(n, 0x00, sizeof n);}
} ans, a[35];
int temp, maxa = 0, T, n, m, q;
void getans(int l, int r) {
    while ((r - l) & 31) {
        r--; 
        if (a[0].get(r))
            ans.flip(r - l);
    }
    int pos = 0;
    while (l & 31) {
        l++; r++;
        pos++;
    }
    l >>= 5, r >>= 5;
    for (int i = l; i < r; i++) {
        ans.n[i - l] ^= a[pos].n[i];
    }
}
void init() {
    for (int i = 0; i < 32; i++) 
        a[i].clear();
    ans.clear();
    maxa = 0;
}
int main() {
    //freopen("1001.in","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d", &T);
    while (T--) {
        init();
        scanf("%d%d%d", &n, &m, &q);
        for (int i = 0; i < n; i++) {
            scanf("%d", &temp);
            for (int j = 0; j < 32; j++) {
                a[j].set(temp + j);
            }
            maxa = max(maxa, temp);
        }
        for (int i = 0; i < m; i++) {
            scanf("%d", &temp);
            for (int j = 0; j <= maxa; j += temp) {
                getans(j, min(maxa + 1, j + temp));
            }
        }
        for (int i = 0; i < q; i++) {
            scanf("%d", &temp);
            printf("%d\n", (int)ans.get(temp));
        }
    }
    return 0;
}

 

 

posted @ 2017-08-09 12:47 UnderSilence 阅读(...) 评论(...) 编辑 收藏