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

题意:

给出一个数列,两种操作

1、区间加

2、区间统计只由4和7组成的数字的个数。

保证每个数都不超过10000

题解:

这题没什么可以讲的,我就来neta一下我写这道题的心路历程吧

首先看到题意,emmm,10000看起来很可做啊……

过了一会,woc,什么鬼?!这玩意是可以区间修改的?

半个小时……

woc,我不会啊

一个小时……

抓狂ing

一个半小时

算了算了,破罐子破摔了,我写个树状数组点修改代替区间修改看看能不能卡过去吧……

一边写一边想

naive,DIV1的E是这么容易水过去的?

然后……

sorry,树状数组是真的可以为所欲为的

emmm,神题神题,rbq,rbq,不得了,不得了,告辞!

我裤子都脱了你就给我看这个?!

算了,发泄完了,代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; int a[],f[],sum[],n,m; void get(int now)
{
if(now*+<=)
{
f[now*+]=;
get(now*+);
}
if(now*+<=)
{
f[now*+]=;
get(now*+);
}
} int lowbit(int x)
{
return (-x)&x;
} void add(int i,int val)
{
while(i<=n)
{
sum[i]+=val;
i+=lowbit(i);
}
} int count(int i)
{
int ans=;
while(i>)
{
ans+=sum[i];
i-=lowbit(i);
}
return ans;
} int main()
{
scanf("%d%d",&n,&m);
get();
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(f[a[i]])
{
add(i,);
}
}
char c[];
int l,r,val;
while(m--)
{
scanf("\n%s",c);
if(c[]=='c')
{
scanf("%d%d",&l,&r);
printf("%d\n",count(r)-count(l-));
}
else
{
scanf("%d%d%d",&l,&r,&val);
for(int i=l;i<=r;i++)
{
if(f[a[i]])
{
add(i,-);
}
a[i]+=val;
if(f[a[i]])
{
add(i,);
}
}
}
}
}

CodeForces 122G Lucky Array(一脸懵逼的树状数组)的更多相关文章

  1. CodeForces - 220B Little Elephant and Array (莫队+离散化 / 离线树状数组)

    题意:N个数,M个查询,求[Li,Ri]区间内出现次数等于其数值大小的数的个数. 分析:用莫队处理离线问题是一种解决方案.但ai的范围可达到1e9,所以需要离散化预处理.每次区间向外扩的更新的过程中, ...

  2. Codeforces 785 E. Anton and Permutation(分块,树状数组)

    Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...

  3. Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数

                                                                    E. Infinite Inversions               ...

  4. Codeforces 899 F. Letters Removing (二分、树状数组)

    题目链接:Letters Removing 题意: 给你一个长度为n的字符串,给出m次操作.每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c. 题解: 看样例可以看出,这题最大的难 ...

  5. Codeforces Round #381 (Div. 2) D dfs序+树状数组

    D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces 703D Mishka and Interesting sum(离线 + 树状数组)

    题目链接  Mishka and Interesting sum 题意  给定一个数列和$q$个询问,每次询问区间$[l, r]$中出现次数为偶数的所有数的异或和. 设区间$[l, r]$的异或和为$ ...

  7. 【Codeforces】Gym 101156E Longest Increasing Subsequences LIS+树状数组

    题意 给定$n$个数,求最长上升子序列的方案数 根据数据范围要求是$O(n\log n)$ 朴素的dp方程式$f_i=max(f_j+1),a_i>a_j$,所以记方案数为$v_i$,则$v_i ...

  8. 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)

    [链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...

  9. Educational Codeforces Round 87 (Rated for Div. 2) D树状数组加二分删除的值

    Sample Input 5 4 1 2 3 4 5 -5 -1 -3 -1 Sample Output 3 思路,首先发现a[i]的值的范围是在1~n之间,每次插入我们可以直接把cnt[a[i]]+ ...

随机推荐

  1. Android屏幕相关概念和适配方法

    参考文档: 1.http://blog.csdn.net/carson_ho/article/details/51234308(略有修改) 2.http://www.cnblogs.com/cheng ...

  2. 阅读《名师讲坛--Android开发实战经典》

    一,专心,快速阅读一本书,直到深入理解,把书读厚,再读薄,你定会有收获. 二,20171214开始阅读<名师讲坛--Android开发实战经典>,但愿自己有所收获.从今天开始养成刻录学习写 ...

  3. redis 创建集群时 出现的错误解决方式

    1. 创建集群时报以下错误 (1)错误1 ./redis-trib.rb create --replicas 1 XXXXXX:5301 XXXXXX:5302 XXXXXX:5303 XXXXXX: ...

  4. Tkinter grid() 方法

        Tkinter grid() 方法:这个的几何管理器组织在父部件的表状结构中的部件.   这的几何管理器组织表状结构中的小部件的父部件. 语法: widget.grid( grid_optio ...

  5. django之设置缓存

    缓存 一句话总结:缓存可以对view.模板.数据进行缓存可以设置缓存在不同的地方(本地内存.redis.系统文档)可以为服务器节省性能.减少用户等待时间. 对于中等流量的网站来说,尽可能地减少开销是必 ...

  6. cento7.3下玩转sphinx

    cento7.5下玩转sphinx 1 安装依赖文件 yum install postgresql-libs unixODBC 2 下载 wget http://sphinxsearch.com/fi ...

  7. 【iBatis】使用resultMap配置返回结果时报错“列名无效”

    使用iBatis联查DEPT.EMP两张表时 采用如下结构 <resultMap id="find_departmentMap" class="com.dto.De ...

  8. Rector模式

    讲到高性能IO绕不开Reactor模式,它是大多数IO相关组件如Netty.Redis在使用的IO模式,为什么需要这种模式,它是如何设计来解决高性能并发的呢? 最最原始的网络编程思路就是服务器用一个w ...

  9. openLayers 3 之入门

    openLayers 3 之入门 openlayer是web GIS客户端开发提供的javascript类库,也是开源框架,可以加载本地数据进行展示地图 1.下载相关引用的js.css文件 2.类似于 ...

  10. python操作docx文档(转)

    python操作docx文档 关于python操作docx格式文档,我用到了两个python包,一个便是python-docx包,另一个便是python-docx-template;,同时我也用到了很 ...