codeforces 145E Lucky Queries
来源:互联网 发布:王者荣耀 芈月 知乎 编辑:程序博客网 时间:2024/05/16 06:23
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits4 and7. For example, numbers47,744,4 are lucky and5, 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 tor 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 62 3 4count 1 3count 1 2add 1 3 2count 1 3add 2 3 3count 1 3
1011
4 54 4 4 4count 1 4add 1 4 3count 1 4add 2 3 40count 1 4
444
给你n个数,实现两种操作,一种操作是把一段区间的数增加某个值,另一个操作是查询一段区间内的数满足"幸运数"要求的总个数
因为题目已保证一个数的值不会超过10000,所以我们可以先把1~10000的幸运数找出来,或者直接打一个表,这样查询一个数是否是幸运数的时间复杂度就是O(1)
我是用树状数组实现的,用线段树应该更快
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <iostream>#define LL long longusing 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;}
- codeforces 145E - Lucky Queries
- codeforces 145E Lucky Queries
- Codeforces Round #104 (Div. 1) E Lucky Queries
- Codeforce E. Lucky Queries 线段树实践
- Codeforces 95E-Lucky Country
- codeforces 797 E Array Queries
- codeforces 797E Array Queries
- Codeforces 797E Array Queries
- Codeforces 797E Array Queries
- codeforces 797E Array Queries
- Cf Round #104 (Div. 1) E Lucky Queries 线段树
- 线段数练习一: CF145E E. Lucky Queries
- CodeForces E. Lucky Array 幸运数列
- CodeForces 266E More Queries to Array...
- Codeforces 797E Array Queries 分块思想
- Educational Codeforces Round 19 E. Array Queries
- Codeforces-797E-Array Queries(dp)
- Educational Codeforces Round 19-E. Array Queries
- Linux初学(CnetOS Linux7)之目录配置--FHS(Filesystem Hierarchy Standard)
- ruby on rails 常用的日期取值
- gson解析json数组
- python-pandas绘图
- uva563
- codeforces 145E Lucky Queries
- POJ2533:Longest Ordered Subsequence(LIS)
- SQL注入
- Power of Two
- 使用Mybatis提供的mybatis generator来自动生成model/mapper.java/mapper.xml
- Cannot change version of project facet Dynamic web module to 2.5
- Android 性能优化之内存泄漏的检测与修复
- HDU1258 Sum It Up(DFS)
- (模板题)sdut 3374 数据结构实验之查找二:平衡二叉树(平衡二叉树的建立)