CF1189C.Candies!
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider a sequence of digits of length 2k [a1,a2,…,a2k] . We perform the following operation with it: replace pairs (a2i+1,a2i+2) with (a2i+1+a2i+2)mod10 for 0≤i<2k−1 . For every i where a2i+1+a2i+2≥10 we get a candy! As a result, we will get a sequence of length 2k−1 .
Less formally, we partition sequence of length 2k into 2k−1 pairs, each consisting of 2 numbers: the first pair consists of the first and second numbers, the second of the third and fourth … , the last pair consists of the ( 2k−1 )-th and ( 2k )-th numbers. For every pair such that sum of numbers in it is at least 10 , we get a candy. After that, we replace every pair of numbers with a remainder of the division of their sum by 10 (and don't change the order of the numbers).
Perform this operation with a resulting array until it becomes of length 1 . Let f([a1,a2,…,a2k]) denote the number of candies we get in this process.
For example: if the starting sequence is [8,7,3,1,7,0,9,4] then:
After the first operation the sequence becomes [(8+7)mod10,(3+1)mod10,(7+0)mod10,(9+4)mod10] = [5,4,7,3] , and we get 2 candies as 8+7≥10 and 9+4≥10 .
After the second operation the sequence becomes [(5+4)mod10,(7+3)mod10] = [9,0] , and we get one more candy as 7+3≥10 .
After the final operation sequence becomes [(9+0)mod10] = [9] .
Therefore, f([8,7,3,1,7,0,9,4])=3 as we got 3 candies in total.
You are given a sequence of digits of length n s1,s2,…sn . You have to answer q queries of the form (li,ri) , where for i -th query you have to output f([sli,sli+1,…,sri]) . It is guaranteed that ri−li+1 is of form 2k for some nonnegative integer k .
输入格式
The first line contains a single integer n ( 1≤n≤105 ) — the length of the sequence.
The second line contains n digits s1,s2,…,sn ( 0≤si≤9 ).
The third line contains a single integer q ( 1≤q≤105 ) — the number of queries.
Each of the next q lines contains two integers li , ri ( 1≤li≤ri≤n ) — i -th query. It is guaranteed that ri−li+1 is a nonnegative integer power of 2 .
输出格式
Output q lines, in i -th line output single integer — f([sli,sli+1,…,sri]) , answer to the i -th query.
输入输出样例
输入#1
8 8 7 3 1 7 0 9 4 3 1 8 2 5 7 7
输出#1
3 1 0
输入#2
6 0 1 2 3 3 5 3 1 2 1 4 3 6
输出#2
0 0 1
说明/提示
The first example illustrates an example from the statement.
f([7,3,1,7])=1 : sequence of operations is [7,3,1,7]→[(7+3)mod10,(1+7)mod10] = [0,8] and one candy as 7+3≥10 → [(0+8)mod10] = [8] , so we get only 1 candy.
f([9])=0 as we don't perform operations with it.