Desant 3
Time limit4sMemory limit1024 MB
For each k, count the initial ready/unready rows with k ready soldiers that end with all ready soldiers contiguous after the conditional swaps, modulo 2.
- Level
Hard9 of 10
- Topics
- Bit manipulation, Combinatorics, Divide and conquer
- Solved
- No attempts yet
Statement
Bajtocja is planning to attack Bitocja again. The elite special unit Bajtogrom has soldiers, who lined up in a row at this morning's assembly. General Bajtazar, who is in charge of the landing, numbered their positions from left to right with integers from to .
Each soldier is either ready for the landing, or needs additional training because of the amended law. General Bajtazar wants all soldiers who are ready for the landing to form a contiguous segment of the row. Formally, he wants there to be no triple of positions such that the -th and the -th soldiers are ready, and the -th soldier is not.
This condition may not hold by default, so Bajtazar will issue orders. In the -th order, he tells the soldiers at positions and to communicate with each other and swap their positions. The soldiers swap if and only if the -th soldier is ready for the landing and the -th soldier is not.
Bajtazar has already chosen a sequence of orders and will issue them. However, he does not know how many soldiers are ready or where they are standing. For each integer between and inclusive, he wants to solve the following problem. Consider all initial configurations of ready and unready soldiers in which exactly soldiers are ready. For how many of these configurations will Bajtazar's condition hold after all orders are executed, that is, the ready soldiers form a contiguous segment of the row? Help him compute these values.
Note: Since many beginners take part in the Algorithmic Contests, we decided not to burden you with large numbers. For each , output the remainder of the number of possibilities modulo the prime number 2.
Input
The first line contains two integers and (; ), the number of soldiers in the row and the number of orders.
Each of the next lines contains two integers and (; ), describing the orders as stated in the statement.
Output
In the first and only line, print integers separated by single spaces. The -th of them must be equal to the remainder modulo 2 of the number of initial configurations with exactly ready soldiers for which, after all orders are executed, all ready soldiers form a contiguous segment of the row.
Hint
If only one soldier is initially ready, he certainly forms a contiguous segment of length one. However, there is no situation where two soldiers are ready and end up standing next to each other.
Consider the situation where everyone except the second soldier in the row is ready for the landing. The first order does not change any positions. After the second order, since the first soldier is ready and the second is not, they swap places. The third order again has no effect. Since the first soldier is now not ready and the fourth soldier is ready, they do not swap in the last order. In the end, only the first soldier is not ready. This is the only initial configuration for that ends as Bajtazar intended.
The counts for successive values of are therefore the sequence .