#P7690. [CEOI 2002] A decorative fence
[CEOI 2002] A decorative fence
Description
Richard has just finished building his new house. Now the only thing missing is a nice little wooden fence. He does not know how to make a wooden fence, so he decided to order one. Somehow, he got the ——the flagship resource for nice little wooden fences (note: ACME is a company that makes everything). After reading its preface, he already knows what makes a little wooden fence nice.
A wooden fence consists of planks, placed vertically in a row. In addition, the fence looks nice if and only if the following conditions are satisfied:
- The planks have different lengths, i.e., the lengths are .
- For each plank that has two neighboring planks, it is either larger than both of its neighbors, or smaller than both of its neighbors. (That is, the top of the fence alternates up and down.)
Therefore, each nice fence using planks can be uniquely described by a permutation such that (,) . Conversely, every such permutation describes a nice fence.
Obviously, there can be many different nice wooden fences made of planks. The ACME sales manager decided to sort the nice fences and put them into the catalog in the following way: fence A (represented by the permutation ) comes before fence B (represented by ) if and only if there exists an such that () and (). (That is, comparing which fence appears earlier in the catalog is equivalent to taking their permutations, finding the first position where they differ, and comparing the values at that position.) All nice fences with planks are numbered in the order they appear in the catalog (starting from ). This number is called their catalog number.
After carefully inspecting all the nice little wooden fences, Richard decided to order some of them. He wrote down the number of planks and the catalog number . Later, he met his friends and wanted to show them his fence, but he lost the catalog. The only thing he still has is his notes. Please help him determine what his fence will look like.
Input Format
The first line contains an integer . The next lines each describe one dataset. Each line contains two integers and separated by a space, where is the number of planks in the fence, and is the catalog number of the fence.
Output Format
For each dataset, output one line describing the -th fence with planks in the list. More precisely, if the fence is the permutation , then the corresponding output line should contain the numbers (in the correct order), separated by single spaces.
2
2 1
3 3
1 2
2 3 1
Hint
Constraints
For of the testdata, , . You may assume that the total number of nice little wooden fences with planks fits into a -bit signed integer variable (long long in C/C++, int64 in FreePascal). You may also assume that the input is correct; in particular, is at least and it does not exceed the number of nice fences with planks.
Problem Notes
From CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2002: A decorative fence.
Translated and整理ed by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号