# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13391 | Domo the Train Conductor |
|
13780 | Domo's Perfect Tree |
|
13785 | Camo's Binary Search Tree |
|
Description
Domo is a train conductor, he wants to adjust the train he's driving.
There are five instructions below with the description:
1. AddFront num
Add a train carriage with the index num in front of the train.
2. AddBack num
Add a train carriage with the index num in back of the train.
3. Delete num
Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)
4. DeleteFront
Delete the first element of the train. (If the train is empty, do nothing)
5. Swap
Reverse all train carriages. (If the train is empty, do nothing)
For example:
AddFront 5 makes the train [4, 1] become [5, 4, 1].
AddBack 5 makes the train [4, 1] become [4, 1, 5].
Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].
DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].
Swap makes the train [2, 6, 3] become [3, 6, 2].
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.
This is a partial judge problem, you're asked to implement these 5 functions.
If you get a TLE:
Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!
If you get an MLE:
Remember to free the nodes you've deleted!
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)
the index of each instruction is a positive integer and not greater than 102.
Output
The output only consists of a line denoting the train carriage indices after all the instructions.
It's guaranteed that the output consists of at least one carriage.
Sample Input Download
Sample Output Download
Partial Judge Code
13391.cPartial Judge Header
13391.hTags
Discuss
Description
Domo is a brilliant dog, he wants to find a perfect size Christmas tree, could you help him?
There's a tree with N nodes; the root is node 1.
The size of node i is the sum of the value of all nodes in the subtree whose root is node i.
Can you find all nodes such that the absolute difference between the size of it and X is smaller than D? (i.e. |Size - X| < D)
Here's an example. The following image describes a tree and the member of node 3's subtree, node 6's subtree, and node 4's.
The sample input is the same as the tree above, you can find further information from it.
Hint: the size of node 1 to node 10 is
[19, 2, 10, 4, 7, 2, 1, 2, 1, 1]
Input
Given three integers N and X and D, which represent the number of nodes in the tree, X and D. (1 ≤ N, X, D ≤ 1000)
The next line consists of N integers (V1, V2, ..., VN), representing the value of nodes. (0 ≤ Vi ≤ 20)
For the following N-1 lines, each line consists of two numbers i and j, representing an edge between node i and node j. (1 ≤ i, j ≤ N)
Output
Output the nodes that the absolute difference of its size and X is smaller than D in ascending order, separating every integer with a space.
Remember to print a newline character at the end of the line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Once upon a time, Camo found that a binary search tree is a very powerful tool, so she wants to build it to support her job, could you help her?
There are two instructions below with the description:
1. Insert num
Insert a number into the binary tree. If the number is already in the binary tree, skip it.
2. Print
Print the binary tree in pre-order
This is a partial judge problem, you're asked to implement these 2 functions.
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)
the number of each instruction is a positive integer and not greater than 109.
Output
The output only consists of a line denoting the pre-order binary tree after every Print instruction.
It's guaranteed that for every Print instruction, the tree is not empty.