FattyLovesMangoes's blog

By FattyLovesMangoes, history, 2 years ago, In English

Given an array a (0 <= a[i] <= 2^22) of length N(<=1e5). For every i, you need to find the number of j such that a[i]&a[j] = a[j].

»
2 years ago, # |
  Vote: I like it +42 Vote: I do not like it
for(int i = 0; i < n; i ++)
    f[a[i]] ++;
for(int j = 0; j < 22; j ++) 
    for(int i = 0; i < (1 << 22); i ++)
        if(i >> j & 1) f[i] += f[i ^ (1 << j)];

f[a[i]] is the answer