# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14219 | All Pass Candy |
|
14575 | Group reversion |
|
Description
In the university, there's a tradition where students give out "All Pass Candy" (歐趴糖), or APCs, to their junior peers before midterms, wishing them to get good grades in the upcoming exams.
This year, CSSA (資工系學會) planned to give out the APCs to all first-year students. Since there are so many students, they want to let the students line up in $N$ lines, and a CSSA member would be in charge of giving out candies at the beginning of each line.
However, on the day of the event, Procat (破貓) took a nap, ended up oversleeping and missed the event. Dogeon (鴿子) was playing maimai (洗衣服), and others were busy with their stuff as well. So, Stiff Waist Beast (挺腰獸) has to give out all the candies by himself. Before that, he has to merge all the lines into one. For the sake of fairness, he wants to merge the lines in a way that the student arriving earlier will get the candy first. Please help him merge all the lines.
-
This is a partial judge problem. Input and output are handled by
13584.c
. All you have to do is implement the function
ListNode* mergeLists(ListNode** lists, int n);
, which merges the $n$ non-decreasing singly linked lists into one non-decreasing singly-linked list, and returns the head of the merged list. -
The definition of a singly-linked list node:
typedef struct _ListNode {
int val;
struct _ListNode *next;
} ListNode; -
This is a work of fiction. Any resemblance to actual events or persons is entirely coincidental.
Input
- The first line contains an integer $N$, the number of student lines.
- Each of the following $N$ lines starts with an integer $M_i$, followed by $M_i$ integers $a_{i,1}, a_{i,2}, \ldots, a_{i,M_i}$, representing the information of each line.
- $M_i$ indicates the number of students in the $i$-th line.
- $a_{i,j}$ indicates the arrival order of the $j$-th student in the $i$-th line.
$N$
$M_1 \quad a_{1,1} \quad a_{1,2} \quad \ldots \quad a_{1,M_1}$
$M_2 \quad a_{2,1} \quad a_{2,2} \quad \ldots \quad a_{2,M_2}$
$\enspace \vdots$
$M_N \quad a_{N,1} \quad a_{N,2} \quad \ldots \quad a_{N,M_N}$
Constraints
- $2 \le N \le 10^5$
- $1 \le M_i \le 10^7$
- $1 \le \sum M_i \le 10^7$
- $1 \le a_{i,j} \le 10^9$
- $a_{i,j - 1} \le a_{i,j}$ for $2 \le j \le M_i$
Output
Single line containing $\sum M_i$ integers, representing the students' arrival order in the merged line. Each integer is followed by a space.
Since this is a partial judge problem, you don't have to worry about the output format.
Sample Input Download
Sample Output Download
Partial Judge Code
14219.cPartial Judge Header
14219.hTags
Discuss
Description
The elephant and its friends are still queuing in a line. However, they are all facing the wrong direction, so they decide to reverse their direction in groups.
Since the elephant and its friends are too lazy to call each other by name, they use a lucky number to recognize one another. Therefore, you will receive a linked list where each node contains a lucky number. Your task is to reverse the order of nodes in groups of \(k\) elephants. If the remaining nodes at the end are fewer than \(k\), jsut reverse the rest of them.
The I/O functions are already implemented in the given file. You only need to complete the void solve(Node* head, int l, int r)
fucntion that returns the same dummy head. Your task is to reverse the linked list in each \(k\) group.
You can ignore the warning while compiling: cast to smaller integer type 'int' from 'Node *' (aka 'struct Node *') [-Wpointer-to-int-cast]
There is a restriction: You can only modify the “next” pointer of each node to change the order. If you attempt to modify the node values or return a list containing nodes whose addresses do not belong to the original list, you may receive a wrong answer.
Images are cited from Chiikawa wiki.
Input
The first line contains two integers \(n\) and \(k\), representing the size of the list and the group size.
The second line contains \(n\) integers \(a_1, a_2,...,a_n\), representing the lucky numbers of the elephants.
Contraints
- \(1 \leq n, k \leq 2 \times 10^5\)
- \(1 \leq a_i \leq 10^9\)
Subtask
- (Testcases 1) \(n = k\)
- (Testcases 2-6) No additional constraints.
Output
Output the modified list of lucky numbers, each followed by a space.