A11480 | Tea Queue
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Recently $n$ students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
$i$ -th student comes to the end of the queue at the beginning of $l_{i}$ -th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of $r_{i}$ -th second student $i$ still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
$i$ -th student comes to the end of the queue at the beginning of $l_{i}$ -th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of $r_{i}$ -th second student $i$ still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
输入格式
The first line contains one integer $t$ — the number of test cases to solve ( $1<=t<=1000$ ).
Then $t$ test cases follow. The first line of each test case contains one integer $n$ ( $1<=n<=1000$ ) — the number of students.
Then $n$ lines follow. Each line contains two integer $l_{i}$ , $r_{i}$ ( $1<=l_{i}<=r_{i}<=5000$ ) — the second $i$ -th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every  condition $l_{i-1}<=l_{i}$ holds.
The sum of $n$ over all test cases doesn't exceed $1000$ .
Note that in hacks you have to set $t=1$ .
Then $t$ test cases follow. The first line of each test case contains one integer $n$ ( $1<=n<=1000$ ) — the number of students.
Then $n$ lines follow. Each line contains two integer $l_{i}$ , $r_{i}$ ( $1<=l_{i}<=r_{i}<=5000$ ) — the second $i$ -th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every  condition $l_{i-1}<=l_{i}$ holds.
The sum of $n$ over all test cases doesn't exceed $1000$ .
Note that in hacks you have to set $t=1$ .
输出格式
For each test case print $n$ integers. $i$ -th of them must be equal to the second when $i$ -th student gets his tea, or $0$ if he leaves without tea.
输入输出样例
输入 #1
2 2 1 3 1 4 3 1 5 1 1 2 3
输出 #1
1 2 1 0 2
The example contains $2$ tests:
1. During $1$ -st second, students $1$ and $2$ come to the queue, and student $1$ gets his tea. Student $2$ gets his tea during $2$ -nd second.
2. During $1$ -st second, students $1$ and $2$ come to the queue, student $1$ gets his tea, and student $2$ leaves without tea. During $2$ -nd second, student $3$ comes and gets his tea.
1. During $1$ -st second, students $1$ and $2$ come to the queue, and student $1$ gets his tea. Student $2$ gets his tea during $2$ -nd second.
2. During $1$ -st second, students $1$ and $2$ come to the queue, student $1$ gets his tea, and student $2$ leaves without tea. During $2$ -nd second, student $3$ comes and gets his tea.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted