← 返回 rippling 的题目列表Task Management Filtering and Sorting
类型:online_judge
Problem: Filtering and Sorting Tasks in a Task Management System
Implement a simplified Task Management query feature.
There are n tasks. Each task has the following fields:
id: a unique task ID string
assignee: the person assigned to the task
status: one of TODO, IN_PROGRESS, DONE, CANCELED
priority: an integer from 1 to 5; a larger number means higher priority
created_at: an integer timestamp
due_at: an integer timestamp; -1 means the task has no due date
Then there are q queries. For each query, you need to:
Filter tasks by the given conditions;
Sort the remaining tasks using a multi-field sorting specification;
Output the first limit task IDs.
Input Format
n
id assignee status priority created_at due_at
...
q
assignee_filter status_filter min_priority sort_spec limit
...
Where:
assignee_filter: if it is *, do not filter by assignee; otherwise keep only tasks whose assignee equals this value.
status_filter: if it is *, do not filter by status; otherwise it is a comma-separated list, such as TODO,IN_PROGRESS.
min_priority: keep only tasks with priority >= min_priority.
sort_spec: a comma-separated list of sorting fields. Each field has format field:order.
field can be one of due, priority, created, id.
order can be asc or desc.
Example: due:asc,priority:desc,created:asc
limit: the maximum number of task IDs to output.
Sorting Rules
Compare tasks according to the fields in sort_spec from left to right.
Field mapping:
due means due_at
priority means priority
created means created_at
id means id
Special rule:
When sorting by due, tasks with due_at = -1 have no due date. They should always be placed after tasks with a valid due date, regardless of ascending or descending order.
If all specified sorting fields are equal, use id in ascending lexicographical order as the final tie-breaker.
Output Format
For each query, print one line:
If there are matching tasks, print their IDs separated by spaces;
Otherwise, print EMPTY.
Constraints
1 <= n <= 10^4
1 <= q <= 10^3
1 <= priority <= 5
created_at > 0
due_at = -1 or due_at > 0
All task IDs are unique.
Example
Input:
5
T1 alice TODO 3 10 50
T2 bob DONE 5 20 40
T3 alice IN_PROGRESS 5 15 -1
T4 alice TODO 4 5 20
T5 bob TODO 2 12 30
2
alice * 1 priority:desc,created:asc 10
* TODO,IN_PROGRESS 3 due:asc,priority:desc 10
Output:
T3 T4 T1
T4 T1 T3
Example
Input
5
T1 alice TODO 3 10 50
T2 bob DONE 5 20 40
T3 alice IN_PROGRESS 5 15 -1
T4 alice TODO 4 5 20
T5 bob TODO 2 12 30
1
alice * 1 priority:desc,created:asc 10
Output
T3 T4 T1