atcoder#ARC151D. [ARC151D] Binary Representations and Queries
[ARC151D] Binary Representations and Queries
Score : points
Problem Statement
You are given an integer sequence of length .
Additionally, queries are given. For each , the -th query is represented by two integers and and asks you to perform the operation below.
For each in this order, do the following.
- First, let be the binary representation of with digits. Additionally, let be the integer represented by the binary representation after flipping the bit (changing to and to ).
- Then, if , add the value of to .
Print each element of , modulo , after processing all the queries in the order they are given in the input.
What is binary representation with $N$ digits?
The binary representation of an non-negative integer () with digits is the unique sequence of length consisting of and that satisfies:
- .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
For each , print the remainder when dividing after processing all the queries by , separated by spaces, in the following format:
2 2
0 1 2 3
1 1
0 0
2 6 2 5
The first query asks you to do the following.
- For , we have and . Since , skip the addition.
- For , we have and . Since , skip the addition.
- For , we have and . Since , add the value of to . Now we have .
- For , we have and . Since , add the value of to . Now we have .
The second query asks you to do the following.
- For , we have and . Since , add the value of to . Now we have .
- For , we have and . Since , skip the addition.
- For , we have and . Since , add the value of to . Now we have .
- For , we have and . Since , skip the addition.
Thus, will be after processing all the queries.
3 10
606248357 338306877 919152167 981537317 808873985 845549408 680941783 921035119
1 1
0 0
0 0
0 0
0 1
0 1
0 1
2 0
2 0
2 0
246895115 904824001 157201385 744260759 973709546 964549010 61683812 205420980