react 前端框架如何驱动企业数字化转型与创新发展
1205
2022-10-05
codeforces 121E Lucky Array
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has an array consisting of n numbers. He wants to perform m operations of two types:
add l r d — add an integer d to all elements whose indexes belong to the interval from l to r, inclusive (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ 104); count l r — find and print on the screen how many lucky numbers there are among elements with indexes that belong to the interval from l to r inclusive (1 ≤ l ≤ r ≤ n). Each lucky number should be counted as many times as it appears in the interval. Petya has a list of all operations. The operations are such that after all additions the array won’t have numbers that would exceed 104. Help Petya write a program that would perform these operations.
Input The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of numbers in the array and the number of operations correspondingly. The second line contains n positive integers, none of which exceeds 104 — those are the array numbers. Next m lines contain operations, one per line. They correspond to the description given in the statement.
It is guaranteed that after all operations are fulfilled each number in the array will not exceed 104.
Output For each operation of the second type print the single number on the single line — the number of lucky numbers in the corresponding interval.
Examples Input 3 6 2 3 4 count 1 3 count 1 2 add 1 3 2 count 1 3 add 2 3 3 count 1 3 Output 1 0 1 1 Input 4 5 4 4 4 4 count 1 4 add 1 4 3 count 1 4 add 2 3 40 count 1 4 Output 4 4 4 Note In the first sample after the first addition the array will look in the following manner:
4 5 6
After the second addition:
4 8 9
The second sample after the first addition:
7 7 7 7
After the second addition:
7 47 47 7
题意 要求我们求一段区间内 幸运数字有多少个 对于幸运数字的定义是:只能包含十进制下的4&7而且题目保证这个他加的数最终不会超过1e4那么我们考虑这题是否和有一个开根号的那题相似呢 大概leoly说很像呢 所以做法就是 我对于线段树上每个点我去储存d[i]表示我的值到距离我最近的那个幸运数字的差是多少 然后维护一个这些值的最小值 维护一下这个最小值最早出现在哪里 再维护一下我最小值一共有几个 然后修改的时候我相当于是区间减法 然后如果这个整个所有1~n中出现了负数 那么我就定位到第一个负数出现在哪里把他改成距离下一个幸运数字的大小 然后重新更新上去 最后直到我1~n中不再有<0的数出现即可 询问的时候只需要询问我最小值为0的数有多少个即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~