Binary String Toggle
InterviewTime limit2sMemory limit512 MB
Apply U range-toggle operations to an all-zero binary string and print the lexicographically largest string among all U+1 intermediate states.
- Level
Medium7 of 10
- Topics
- Prefix sum, Greedy, Implementation
- Solved
- No attempts yet
Problem
There is a binary string of length whose characters are all 0. You apply toggle operations to it. The -th operation turns into , so once all operations are done the string is .
The -th operation is given as two integers and . It flips every character in the range . Both ends included, every 1 inside that range becomes 0 and every 0 becomes 1.
Applying all operations gives the strings . Write a program that finds the one that comes last in lexicographic order among these strings.
Input
The first line contains and . ()
Each of the next lines contains and . ()
Output
On the first line, print the string that comes last in lexicographic order among the strings.
Hint
For the example input, the string changes in this order.
- =
0000000000 - =
0000000011 - =
0000011100 - =
0000011111 - =
1111100011 - =
1100000011 - =
1110000011 - =
1101000011 - =
1110111101 - =
1111000001 - =
1111001001