time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

线段树区间修改,单点查询

if(v) single_change(root,i,v);

这一句没写 T成傻逼了。

指针线段树比数组线段树慢近300ms

数组线段树比树状数组慢近1000ms

屠龙宝刀点击就送

线段树代码

#include <ctype.h>
#include <cstdio>
const int N = 1e6+;
bool IsLucky[N];
int dis[N],n,m,Lucky[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
inline void Read(int &x)
{
bool f=;
register char ch=getchar();
for(x=;!isdigit(ch);ch=getchar()) if(ch=='-') f=;
for(;isdigit(ch);ch=getchar()) x=x*+ch-'';
x=f?-x:x;
}
struct Segment
{
int l,r,mid,flag,upval;
Segment * ch[];
Segment()
{
ch[]=ch[]=NULL;
flag=upval=;
}
};
inline void pushup(Segment *&k) {k->upval=k->ch[]->upval+k->ch[]->upval;}
void build(Segment *&k,int l,int r)
{
k=new Segment;
k->l=l;k->r=r;
if(l==r)
{
if(IsLucky[dis[l]]) k->upval+=;
return;
}
k->mid=l+r>>;
build(k->ch[],l,k->mid);
build(k->ch[],k->mid+,r);
pushup(k);
}
int query(Segment *&k,int l,int r)
{
if(k->l==l&&k->r==r)
return k->upval;
if(l>k->mid) return query(k->ch[],l,r);
else if(r<=k->mid) return query(k->ch[],l,r);
else return query(k->ch[],l,k->mid)+query(k->ch[],k->mid+,r);
}
void single_change(Segment *&k,int t,int v)
{
if(k->l==k->r)
{
k->upval+=v;
return;
}
if(t<=k->mid) single_change(k->ch[],t,v);
else single_change(k->ch[],t,v);
pushup(k);
}
int Main()
{
Read(n);
Read(m);
for(int i=;i<=;++i) IsLucky[Lucky[i]]=;
for(int i=;i<=n;++i) scanf("%d",&dis[i]);
Segment *root=new Segment;
build(root,,n);
char str[];
for(int x,y,z;m--;)
{
scanf("%s",str+);
if(str[]=='c')
{
Read(x);
Read(y);
printf("%d\n",query(root,x,y));
}
else
{
Read(x);
Read(y);
Read(z);
for(int i=x;i<=y;++i)
{
int v=;
if(IsLucky[dis[i]]) --v;
dis[i]+=z;
if(IsLucky[dis[i]]) ++v;
if(v) single_change(root,i,v);
}
}
}
return ;
}
int sb=Main();
int main(int argc,char *argv[]){;}

树状数组

#include <ctype.h>
#include <cstdio>
const int N = 1e6+;
bool IsLucky[N];
int tag[N],dis[N],n,m,Lucky[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
inline void Read(int &x)
{
bool f=;register char ch=getchar();
for(x=;!isdigit(ch);ch=getchar()) if(ch=='-') f=;
for(;isdigit(ch);ch=getchar()) x=x*+ch-'';
x=f?-x:x;
}
inline int lowbit(int x) {return x&(-x);}
inline void modify(int x,int y)
{
for(;x<=n;x+=lowbit(x)) tag[x]+=y;
}
inline int ask(int x)
{
int sum=;
for(;x;x-=lowbit(x)) sum+=tag[x];
return sum;
}
int main()
{
Read(n);Read(m);
for(int i=;i<=;++i) IsLucky[Lucky[i]]=;
for(int i=;i<=n;++i) {Read(dis[i]);if(IsLucky[dis[i]]) modify(i,);}
char str[];
for(int x,y,z;m--;)
{
scanf("%s",str+);
if(str[]=='c')
{
Read(x);
Read(y);
printf("%d\n",ask(y)-ask(x-));
}
else
{
Read(x);
Read(y);
Read(z);
for(int i=x;i<=y;++i)
{
int v=;
if(IsLucky[dis[i]]) --v;
dis[i]+=z;
if(IsLucky[dis[i]]) ++v;
if(v) modify(i,v);
}
}
}
return ;
}

最新文章

  1. 用NSAttributedString实现简单的图文混排
  2. 开源服务专题之------ssh防止暴力破解及fail2ban的使用方法
  3. matlab 解方程组
  4. django概述
  5. c#获取今天星期几
  6. Java的哪些事
  7. android开发之socket快传文件以及消息返回
  8. &lt;七&gt;面向对象分析之UML核心元素之包
  9. linux 下使用 cmake安装mysql
  10. 设计模式_Iterator_迭代器模式
  11. 磁珠(FB)的原理
  12. Windsock套接字I/O模型学习 --- 第二章
  13. synchronized优化
  14. 【Python】 获取MP3信息replica
  15. 简易RPC
  16. 第六十五天 js操作
  17. 操作日志的设计小结by大熊
  18. 查询当前局域网下所有IP和物理网卡地址
  19. BT.656 NTSC制式彩条生成模块(verilog)
  20. python+selenium环境安装

热门文章

  1. char的定义在iOS和Android下是不同的
  2. Kefa and Watch
  3. IsPostBack深入探讨
  4. Spring入门(四):使用Maven管理Spring项目
  5. 使用fastadmin的页面异常模板
  6. 15.split分割注意事项
  7. Java 定时任务(转)
  8. iReport - 无法正常启动的解决方法
  9. swift SqliteDB使用
  10. redis配置配置文件