#abc305d. D - Sleep Log
D - Sleep Log
Score : points
问题描述
高桥有一份睡眠记录。该记录表示为一个奇数长度的序列 ,其中奇数位置的元素代表他起床的时间,偶数位置的元素代表他睡觉的时间。更正式地说,在开始记录睡眠后,他有以下睡眠时段:
- 对于满足 的每个整数 ,他在开始记录睡眠后的精确 分钟时入睡,并在开始记录睡眠后的精确 分钟时醒来。
- 他在其他任何时间都没有入睡或醒来。
回答接下来的 个问题。对于第 个问题,给定一对整数 ,满足 。
- 在从开始记录睡眠后精确的 分钟到 分钟这 分钟期间,高桥总共睡了多少分钟?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi keeps a sleep log. The log is represented as an odd-length sequence , where odd-numbered elements represent times he got up, and even-numbered elements represent times he went to bed. More formally, he had the following sleep sessions after starting the sleep log.
- For every integer such that , he fell asleep exactly minutes after starting the sleep log and woke up exactly minutes after starting the sleep log.
- He did not fall asleep or wake up at any other time.
Answer the following questions. For the -th question, you are given a pair of integers such that .
- What is the total number of minutes for which Takahashi was asleep during the minutes from exactly minutes to minutes after starting the sleep log?
Constraints
- is odd.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in lines. The -th line should contain an integer answering to the -th question.
Sample Input 1
7
0 240 720 1320 1440 1800 2160
3
480 1920
720 1200
0 2160
Sample Output 1
480
0
960
Takahashi slept as shown in the following figure.
The answers to each question are as follows.
- Between minutes and minutes after starting the sleep log, Takahashi slept from minutes to minutes, from minutes to minutes, and from minutes to minutes in sleep sessions. The total sleep time is minutes.
- Between minutes and minutes after starting the sleep log, Takahashi did not sleep. The total sleep time is minutes.
- Between minutes and minutes after starting the sleep log, Takahashi slept from minutes to minutes, from minutes to minutes, and from minutes to minutes in sleep sessions. The total sleep time is minutes.
Therefore, the three lines of the output should contain , , and .
Sample Input 2
21
0 20 62 192 284 310 323 324 352 374 409 452 486 512 523 594 677 814 838 946 1000
10
77 721
255 541
478 970
369 466
343 541
42 165
16 618
222 592
730 983
338 747
Sample Output 2
296
150
150
49
89
20
279
183
61
177
update @ 2024/3/10 08:36:31