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 ;
}

codeforces 121 E. Lucky Array的更多相关文章

  1. Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array 分块

    E. Lucky Array time limit per test 4 seconds memory limit per test 256 megabytes input standard inpu ...

  2. Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

    E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers w ...

  3. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  4. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  5. CodeForces 122G Lucky Array(一脸懵逼的树状数组)

    Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal re ...

  6. Lucky Array Codeforces - 121E && Bear and Bad Powers of 42 Codeforces - 679E

    http://codeforces.com/contest/121/problem/E 话说这题貌似暴力可A啊... 正解是想出来了,结果重构代码,调了不知道多久才A 错误记录: 1.线段树搞混num ...

  7. Lucky Array CodeForces - 121E (线段树,好题)

    题目链接 题目大意: 定义只含数字$4,7$的数字为幸运数, 给定序列, 区间加正数, 区间询问多少个幸运数 题解: 对于每一个数, 求出它和第一个比它大的幸运数之差, 则问题转化为区间加,查询$0$ ...

  8. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  9. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

随机推荐

  1. AngularJS系统学习之Directive(指令)

    本文转自https://www.w3ctech.com/topic/1612 原文作者: Nicolas Bevacqua 原文:AngularJS’ Internals In Depth, Part ...

  2. jquery : eval() 解析json的注意

    jquery eval解析JSON中的注意点介绍 来在:http://www.jb51.net/article/40842.htm 在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: ...

  3. UVa 1627 Team them up! (01背包+二分图)

    题意:给n个分成两个组,保证每个组的人都相互认识,并且两组人数相差最少,给出一种方案. 析:首先我们可以知道如果某两个人不认识,那么他们肯定在不同的分组中,所以我们可以根据这个结论构造成一个图,如果两 ...

  4. 201621123016 《Java程序设计》第十四周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 使用数据库技术改造你的系统 2.1 简述如何使用数据库技术改造你的系统.要建立什么表?截图你的表设计. 把我原来 ...

  5. 1004 Counting Leaves (30 分)

    A family hierarchy is usually presented by a pedigree tree. Your job is to count those family member ...

  6. API网络接口

    1.天气 文章:http://segmentfault.com/a/1190000002607883 地址:http://api.lib360.net/open/weather.json?city=北 ...

  7. Codeforces 744C【DFS】

    题意: 给你一幅图,然后有几个特殊点 和不特殊点,给你一些已经连了的边,在保证特殊点不能连的前提下,问最多还能添几条边,双向边 思路: 简单题,就是一个特殊点就是一个集合,然后搜一下,最后把还有没连的 ...

  8. 聪明的质监员(codevs 1138)

    题目描述 Description 小 T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有n 个矿石,从1到n 逐一编号,每个矿石都有自己的重量wi 以及价值vi.检验矿产的流程是:见图   ...

  9. 新手安装 hadoop、hive和hbase 笔记

    系统是ubuntu 12.04 , hadoop版本是1.2.1 , hive版本是0.12 , hbase版本我忘记了,不好意思首先是配置好hostnamevi /etc/hosts写入你要配置的i ...

  10. python使用rabbitmq实现简单的消息转发

    准备: 1.下载elang语言的支持环境http://www.erlang.org/download.html (rabbitmq使用它开发的) 2.下载rabbitmq软件http://www.ra ...