Brperm

Time limit: 3s Memory limit: 256MB Input: Output:

Note: in the following statement, b1bk\overline{b_1 \dots b_k} represents an integer written out in binary notation, where b1b_1 is the most significant bit, and bkb_k 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 2k2^k people are dancing. Then, the person at position b1bk\overline{b_1 \dots b_k} goes to position bkb1\overline{b_k \dots b_1} (indexed from 00).

Roxanne noticed also that every person on BR-PERM wears one of 2626 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 k=2k = 2, we have a row of four dancers 00, 11, 22, 33, that after the dance become ordered like so: 00, 22, 11, 33. So, the sequence of clothing colors abba is nice, but abca is not.

Task

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 nn dancers, and ask her several questions: "is the sequence of length 2k2^k starting at dancer ii nice?".

Interaction protocol

The contestant must implement two functions. The first of them is the following:

void init (int n, const char s[]); 

This function will be called exactly once, at the beginning of the interaction, and supplies the contestant with the string of clothing colors of the dancers, through parameter ss.

The second function that the contestant must implement is:

int query (int i, int k);

This function will be called exactly QQ times and must return 11 if and only if the contiguous subsequence of ss starting at the ithi^{\text{th}} dancer (indexed from 00), and of length 2k2^k, is nice. It must return 00 otherwise.

Constraints and clarifications

  • 1N500 0001 \leq N \leq 500 \ 000
  • 1Q500 0001 \leq Q \leq 500 \ 000
# Points Constraints
1 13 1N,Q1 0001 \leq N, Q \leq 1 \ 000
2 37 1N,Q100 0001 \leq N, Q \leq 100 \ 000
3 17 ss contains only the characters a and b. The colors are independently randomly chosen with a certain fixed probability for each testcase.
4 33 No additional constraints

Example

input

init(8, "axxyxxyb")

output

query(0, 3) = true
query(1, 1) = true
query(1, 2) = false
query(3, 2) = true

Log in or sign up to be able to send submissions!