A1137 | [COCI-2007_2008-olympiad]#2 KOLEKCIJA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Igor has a huge collection of folk hits on his computer, containing N songs numbered 1 to N.
The collection is so big that it is not possible to display all songs at once on his display. Because of this, while a song is playing, only K consecutive songs from the collectionare displayed on the screen. Of course, the K consecutive songs necessarily include the song currently playing.
When a song first appears on the display, the software needs to access its file on disk and read metadata like artist and song name. This metadata is stored in the computer's memory so that, if the song reappears on display, the file doesn't need to be opened again.
Your program will be given the songs Igor wants to listen to, in the order in which he wants to do it.
For each song, determine the interval of songs which will be displayed while it is playing, so that the total number of files that need to be accessed on disk is the smallest possible.
Note: The solution may not be unique.
The collection is so big that it is not possible to display all songs at once on his display. Because of this, while a song is playing, only K consecutive songs from the collectionare displayed on the screen. Of course, the K consecutive songs necessarily include the song currently playing.
When a song first appears on the display, the software needs to access its file on disk and read metadata like artist and song name. This metadata is stored in the computer's memory so that, if the song reappears on display, the file doesn't need to be opened again.
Your program will be given the songs Igor wants to listen to, in the order in which he wants to do it.
For each song, determine the interval of songs which will be displayed while it is playing, so that the total number of files that need to be accessed on disk is the smallest possible.
Note: The solution may not be unique.
输入格式
The first line contains two integers N and K (1 ≤ K < N < 1 000 000 000), the number of songs in the collection and the number of songs displayed.
The second line contains the integer M (1 ≤ M ≤ 300 000), the number of songs Igor will listen to.
The next M lines contain the indices of the songs Igor will listen to. All numbers will be between 1 and N and no song will appear more than once.
The second line contains the integer M (1 ≤ M ≤ 300 000), the number of songs Igor will listen to.
The next M lines contain the indices of the songs Igor will listen to. All numbers will be between 1 and N and no song will appear more than once.
输出格式
Output should consist of M+1 lines.
On the first line output the smallest possible number of files to access while playing Igor's playlist.
After this, for each song S, in order in which they are given, output a pair of integers A and B, meaning that while song S is playing, songs A through B (inclusive) are displayed on screen. A and B must satisfy the conditions 1 ≤ A ≤ S ≤ B ≤ N, and B−A+1 = K.
On the first line output the smallest possible number of files to access while playing Igor's playlist.
After this, for each song S, in order in which they are given, output a pair of integers A and B, meaning that while song S is playing, songs A through B (inclusive) are displayed on screen. A and B must satisfy the conditions 1 ≤ A ≤ S ≤ B ≤ N, and B−A+1 = K.
输入输出样例
输入 #1
10 3 5 4 5 8 7 6
输出 #1
5 4 6 4 6 6 8 6 8 6 8
输入 #2
15 4 6 6 14 11 3 8 5
输出 #2
10 3 6 11 14 11 14 3 6 5 8 3 6
输入 #3
1000 301 3 300 500 700
输出 #3
401 300 600 350 650 400 700
An output which is not completely correct, but the first line (the least number of file to access) is
correct, will score 50% points for that test case.
correct, will score 50% points for that test case.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted