Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits4 and 7. For example, numbers47, 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 lrd — add an integerd to all elements whose indexes belong to the interval froml to r, inclusive(1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ 104);
- count lr — find and print on the screen how many lucky numbers there are among elements with indexes that belong to the interval froml 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 exceed104. 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 exceeds104 — those are the array numbers. Nextm 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 exceed104.
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.
Sample 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
1
0
1
1
4 5
4 4 4 4
count 1 4
add 1 4 3
count 1 4
add 2 3 40
count 1 4
4
4
4
给你n个数,实现两种操作,一种操作是把一段区间的数增加某个值,另一个操作是查询一段区间内的数满足"幸运数"要求的总个数
因为题目已保证一个数的值不会超过10000,所以我们可以先把1~10000的幸运数找出来,或者直接打一个表,这样查询一个数是否是幸运数的时间复杂度就是O(1)
我是用树状数组实现的,用线段树应该更快
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <iostream> #define LL long long using namespace std; int a[100001],c[100002],kk[10002]={0}; int maxn; inline int lowbit(int a) { return a&(-a); } void add(int x,int num) { while(x<=maxn) { c[x]+=num; x+=lowbit(x); } } int getsum(int x) { int sum=0; while(x) { sum+=c[x]; x-=lowbit(x); } return sum; } bool jug(int a) { while(a) { if(a%10!=4&&a%10!=7) return 0; a/=10; } return 1; } int main() { int i,ans,n,m,b,a1,c1,x1,x2; char s[10]; for(i=1;i<=10001;i++) if(jug(i)) kk[i]=1; while(~scanf("%d %d",&n,&m)) { maxn=n; for(i=0; i<=n+1; i++) c[i]=0; for( i=1; i<=n; i++) { scanf("%d",&a[i]); if(kk[a[i]]==1) add(i,1); } while(m--) { scanf("%s",s); if(s[0]=='c') { scanf("%d %d",&a1,&b); printf("%d\n",getsum(b)-getsum(a1-1)); } else { scanf("%d %d %d",&a1,&b,&c1); for(i=a1; i<=b; i++) { x1=kk[a[i]]; a[i]+=c1; x2=kk[a[i]]; if(x1==1&&x2==0) add(i,-1); else if(x1==0&&x2==1) add(i,1); } } } } return 0; }