# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 170 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
5 | -is-this-fft- | 158 |
7 | adamant | 154 |
7 | Dominater069 | 154 |
9 | awoo | 153 |
10 | luogu_official | 152 |
Name |
---|
Oh, I did it that way! Observe the following pattern (bi represents the ith lower bit of n (1-based)):
Suppose that n has exactly one bit: then, your array will be b1.
If n has two bits, the final array will be b2, b1, b2.
If n has three bits, the final array will be b3, b2, b3, b1, b3, b2, b3.
If n has four bits, the final array will be b4, b3, b4, b2, b4, b3, b4, b1, b4, b3, b4, b2, b4, b3, b4.
You can see that in general, if the lowest significant bit of i is the k th one (1-based), then, the bit in the i th position (1-based) in the array of bits you get is bm + 1 - k, where m is the number of bits n has. This can be formally proved with induction. (Hint: notice that the way the array is built is symmetrical).
Then, for this solution, you only need to iterate from l to r and find those bits. My submission: 24858226
in your code , i & -i ,i dont understand this ,
i& - i gives you the least significant bit of number i. It is the same as (i & (i-1)). The least significant bit of a number is the rightmost bit that is not 0.