CF1217E.Sum Queries?
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that holds for every position, then the multiset is balanced. Otherwise it's unbalanced.
For example, multiset {20,300,10001} is balanced and multiset {20,310,10001} is unbalanced:
The red digits mark the elements and the positions for which these elements have the same digit as the sum. The sum of the first multiset is 10321 , every position has the digit required. The sum of the second multiset is 10331 and the second-to-last digit doesn't appear in any number, thus making the multiset unbalanced.
You are given an array a1,a2,…,an , consisting of n integers.
You are asked to perform some queries on it. The queries can be of two types:
- 1 i x — replace ai with the value x ;
- 2 l r — find the unbalanced subset of the multiset of the numbers al,al+1,…,ar with the minimum sum, or report that no unbalanced subset exists.
Note that the empty multiset is balanced.
For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.
输入格式
The first line contains two integers n and m ( 1≤n,m≤2⋅105 ) — the number of elements in the array and the number of queries, respectively.
The second line contains n integers a1,a2,…,an ( 1≤ai<109 ).
Each of the following m lines contains a query of one of two types:
- 1 i x ( 1≤i≤n , 1≤x<109 ) — replace ai with the value x ;
- 2 l r ( 1≤l≤r≤n ) — find the unbalanced subset of the multiset of the numbers al,al+1,…,ar with the lowest sum, or report that no unbalanced subset exists.
It is guaranteed that there is at least one query of the second type.
输出格式
For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.
输入输出样例
输入#1
4 5 300 10001 20 20 2 1 3 1 1 310 2 1 3 2 3 3 2 3 4
输出#1
-1 330 -1 40
说明/提示
All the subsets of multiset {20,300,10001} are balanced, thus the answer is -1.
The possible unbalanced subsets in the third query are {20,310} and {20,310,10001} . The lowest sum one is {20,310} . Note that you are asked to choose a subset, not a subsegment, thus the chosen elements might not be adjancent in the array.
The fourth query includes only the empty subset and subset {20} . Both of them are balanced.
The last query includes the empty subset and the subsets {20} , {20} and {20,20} . Only {20,20} is unbalanced, its sum is 40 . Note that you are asked to choose a multiset, thus it might include equal elements.