Freight Train
InterviewTime limit10sMemory limit1024 MB
Given Bitek's list as a subsequence of Bajtek's list, mark each wagon 1 if Bitek could have recorded it and 0 if he certainly missed it.
- Level
Medium6 of 10
- Topics
- Two pointers, Binary search, Array
- Solved
- No attempts yet
Problem
Bajtek and Bitek enjoy watching trains that pass near their home. They love freight trains most, because those are usually very long and have varied wagons. The boys decided to record which types of wagons make up each train. For simplicity, the wagon types are numbered from 1 to . Wagons of the same type are indistinguishable to the boys.
When a train passes, both boys write down the types of the wagons in their notebooks, in order. Bajtek is older and can record the types of all wagons without mistakes. Bitek is younger and not yet as skilled at writing. Sometimes, before he manages to write down a wagon's type, the next wagons have already passed, and Bitek does not notice them. So some wagons may be missing from Bitek's list.
The boys are now analyzing their notes. They want to determine which wagons of the train Bitek could have recorded, and which ones he certainly missed.
Input
The first line contains three integers , , and (), which are the length of Bajtek's list (equal to the number of wagons in the train), the length of Bitek's list, and the number of different wagon types.
The second line contains integers from , the wagon types on Bajtek's list. The third line contains integers in the same format, the list of Bitek's list.
You may assume that Bitek may have skipped some wagons from Bajtek's list, but he did not add anything extra. In other words, the input is such that some number of wagons (possibly zero) can be erased from Bajtek's list to obtain Bitek's list.
Output
Print integers separated by single spaces. The -th integer is if the -th wagon could have been recorded by Bitek, or if it certainly could not have been recorded.
Hint
Explanation of the example: Bitek could have recorded the wagons with these numbers:
- 1, 2, 4, and 5,
- 1, 2, 4, and 9,
- 1, 2, 7, and 9,
- 1, 6, 7, and 9,
- or 4, 6, 7, and 9.