Brperm
시간 제한2초메모리 제한1024 MB
색 문자열과 길이 2^k 블록에 대한 비트 반전 순열이 주어질 때, i에서 시작하는 블록이 그 순열에 의해 변하지 않는지 묻는 질의에 답한다.
문제
Note: in the following statement, represents an integer written out in binary notation, where is the most significant bit, and is the least significant bit.
Roxanne the space witch, while riding her broomstick throughout the galaxy, came across a planet in which everybody danced a strange dance: planet Br-perm. In this dance, the participants stand in a line, and then reorder themselves. Suppose people are dancing. Then, the person at position goes to position (indexed from ).
Roxanne noticed also that every person on Br-perm wears one of colors of clothing. These colors are represented by the letters of the Latin alphabet.
The Br-perm-ians place special significance on rows of dancers where the sequence of colors of clothing that people are wearing before and after the dance are the same. They call such sequences nice. For instance, when , we have a row of four dancers , that after the dance become ordered like so: . So, the sequence of clothing colors abba is nice, but abca is not.
The Br-perm-ians have asked Roxanne to help them with a difficult matter (space witches always seem to have to help people with their problems). They show her a long row of dancers, and ask her several questions: “is the sequence of length starting at dancer nice?”