Dhaka Regional ACM ICPC 2016 Preleminary Contest Solution F - Counter RMQ
F. Counter RMQ
Score: 1
CPU: 1s
Memory: 1200MB
CPU: 1s
Memory: 1200MB
You must have heard about the Range Minimum Query (RMQ) problem. If you haven’t, here is a definition:
Given an array A[1 … n] of n integers, the range minimum query RMQ(l, r) (1 ≤ l ≤ k ≤ r ≤ n) returns the value of the minimal element in the specified sub-array A[l … r].
Imagine a program that takes a series of RMQ queries and prints the answers. Is it possible to recover the original sequence? Yes, you are right, it’s not possible for most of the cases, for different possible input arrays A, there could be the same set of answers for a given set of RMQ queries. Why don’t we try finding one such array A?
Given n, (the length of A) and q RMQ queries and their answers in l r RMQ(l, r) format, print any array that produces the answer. For the purpose of this problem, we assume A[i] will be positive and less than or equal to 20000.
Input
The input starts with T, the number of test cases (T ≤ 100). It follows T sets of test cases. Each test case starts with two numbers n andq (1 ≤ n ≤ 100, 1 ≤ q ≤ 20000) denoting the array length and the number of queries. That is followed by q lines. Each of these q lines consists of three integers l, r, RMQ(l, r) as mentioned in the statement. (1 ≤ l ≤ r ≤ n and 1 ≤ RMQ(l, r) ≤ 20000). You can assume that there will always be at least one valid answer consistent with the input.
Output
For each set of inputs, print the test case number followed by the output array, n integers separated by single space. For the output format, please consult the sample input/output. There can be multiple correct answers, you can print anyone.
Sample
Input | Output |
---|---|
1 7 5 1 4 4 4 7 12 2 2 17 1 7 4 4 5 32 | Case 1: 10 17 4 57 32 53 12 |
*Warning: Large I/O file, user faster input output functions.
Comments
Post a Comment