Binary String
Time limit2sMemory limit512 MB
Given a binary string and m operations that insert complements of substrings after position y, print the first k characters of the final string.
- Level
Medium6 of 10
- Topics
- String, Simulation, Recursion
- Solved
- No attempts yet
Problem
You are given a binary string of length , consisting only of 0 and 1.
The indices of start from 1. denotes the substring of from index to index , inclusive.
You apply the following insertion operation times. Each operation takes two integers , and the values of and may differ between operations.
- The inserted string is the complement of , meaning every 0 becomes 1 and every 1 becomes 0.
- The string is inserted immediately after the -th character of . After the insertion, the length of grows by .
- is updated after each operation. The next operation uses the updated .
The goal is to find the first characters of the final after all operations.
For example, let , , , , and apply the operations and in order. The first operation inserts the complement of , which gives S = 01010100110 (the bold part is the inserted text). The second operation inserts the complement of , which gives S = 01010101100110. Since , the answer is the first 12 characters, 010101011001.
Input
The first line contains the number of test cases ().
The first line of each test case contains , , and , separated by spaces.
The second line contains the binary string of length .
Each of the next lines contains two integers and . It is guaranteed that min(the length of just before the -th operation, ).
Also, does not exceed the smaller of the length of the final and .
Output
For each test case, print the string of length on one line.
Hint
- Case 2: 1010 becomes 10010. Since , only the first 4 characters are printed.
- Case 3: 10101100 becomes 1001101100, and then 10011011110010000. Since , only the first 16 characters are printed.