-
-
Notifications
You must be signed in to change notification settings - Fork 144
Open
Description
Problem name: Bitset Xor Shift
Problem ID: bitset_xor_shift
Problem
You are given a binary string s of length (n). Perform (m) operations on it.
Each operation is described by an integer shift, meaning:
[
s \gets s \ \oplus \ (s \gg \text{shift})
]
After each operation, output the number of 1's in s.
Here, (\oplus) represents bitwise XOR.
- If
shift > 0, shiftsto the right. - If
shift < 0, shiftsto the left. - If
shift = 0, no shifting occurs.
Constraint
- (1 \le n, m \le 10^4)
Input
n m
s
shift_1
shift_2
...
shift_m
sis a binary string of lengthn.- Each
shift_iis an integer satisfying (0 \le |\text{shift}_i| < n).
Output
c_1
c_2
...
c_m
c_iis the number of1's insafter the (i)-th operation.
Example
Input:
5 3
10101
2
-1
0
Output:
1
0
0
Explanation:
10101 ^ (10101 >> 2) = 10101 ^ 00101 = 10000→ 1's count = 110000 ^ (10000 << 1) = 10000 ^ 10000 = 00000→ 1's count = 000000 ^ (00000 >> 0) = 00000→ 1's count = 0
Metadata
Metadata
Assignees
Labels
No labels