Two Sequences
Time limit3sMemory limit1024 MB
For each query, find the k-th element of the lexicographically smallest merge of the prefixes A[1..a] and B[1..b].
- Level
Hard9 of 10
- Topics
- String, Greedy, Segment tree
- Solved
- No attempts yet
Problem
Two sequences and are given. Starting from an empty sequence , perform a move exactly times. Define as the lexicographically smallest sequence that can be the final state of .
A move is one of the following two actions.
- If is not empty, remove the first element of and append it to the end of .
- If is not empty, remove the first element of and append it to the end of .
You are given an integer sequence of length and an integer sequence of length .
Write a program that processes the following query.
a b k: Print the -th number of .
Input
The first line contains , , and , separated by spaces. ()
The second line contains , separated by spaces. ()
The third line contains , separated by spaces. ()
Each of the next lines contains a query , , and , separated by spaces. (; ; )
Output
Print lines. Print the answer to each query in the order the queries are given.