A1117 | [COCI-2007_2008-contest3]#5 REDOKS
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Luka is not paying attention in class again, while the teacher is explaining redox reactions. Instead of paying attention, he is playing with analog dials.
An analog dial is a small device which always shows one digit between 0 and
9. It also contains a small button which increases the number by 1 (unless it is 9, in which case it is changed to 0).
Luka has N such dials on his desk, numbered 1 to N left to right, and two sheets of paper for him to write on.
Luka's game starts with him setting the dials in some starting configuration, which he then writes onto the first sheet. Luka then does the following M times:
• Choose two integers A and B (1 ≤ A ≤ B ≤ N) and write them down on the first sheet.
• Calculate the sum of numbers on dials numbered between A and B (inclusive), and write the sum down on the second sheet.
• Press the button once on all dials numbered between A and B.
Just as he had finished his game, the teacher noticed him, and took away all his dials and the second sheet of paper.
Given the contents of the first sheet, help him calculate the numbers on the second sheet.
An analog dial is a small device which always shows one digit between 0 and
9. It also contains a small button which increases the number by 1 (unless it is 9, in which case it is changed to 0).
Luka has N such dials on his desk, numbered 1 to N left to right, and two sheets of paper for him to write on.
Luka's game starts with him setting the dials in some starting configuration, which he then writes onto the first sheet. Luka then does the following M times:
• Choose two integers A and B (1 ≤ A ≤ B ≤ N) and write them down on the first sheet.
• Calculate the sum of numbers on dials numbered between A and B (inclusive), and write the sum down on the second sheet.
• Press the button once on all dials numbered between A and B.
Just as he had finished his game, the teacher noticed him, and took away all his dials and the second sheet of paper.
Given the contents of the first sheet, help him calculate the numbers on the second sheet.
输入格式
The first line contains two integers N and M (1 ≤ N ≤ 250000, 1 ≤ M ≤ 100000).
The second line contains the initial configuration of the dials, N decimal digits with no spaces. The first digit is the number initially on dial 1, the second digit the number on dial 2 and so on.
Each of the following M lines contains two integers A and B (1 ≤ A ≤ B ≤ N).
The second line contains the initial configuration of the dials, N decimal digits with no spaces. The first digit is the number initially on dial 1, the second digit the number on dial 2 and so on.
Each of the following M lines contains two integers A and B (1 ≤ A ≤ B ≤ N).
输出格式
Output M lines, the sums calculated by Luka, in order in which he calculated them.
输入输出样例
输入 #1
4 3 1234 1 4 1 4 1 4
输出 #1
10 14 18
输入 #2
4 4 1234 1 1 1 2 1 3 1 4
输出 #2
1 4 9 16
输入 #3
7 5 9081337 1 3 3 7 1 3 3 7 1 3
输出 #3
17 23 1 19 5
In 30% of all test cases, the numbers N and M will be less than 1000.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted