博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 122G Lucky Array(一脸懵逼的树状数组)
阅读量:4670 次
发布时间:2019-06-09

本文共 3597 字,大约阅读时间需要 11 分钟。

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
#include
#include
#include
using namespace std;int a[100010],f[100010],sum[100010],n,m;void get(int now){ if(now*10+7<=10000) { f[now*10+7]=1; get(now*10+7); } if(now*10+4<=10000) { f[now*10+4]=1; get(now*10+4); }}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=0; while(i>0) { ans+=sum[i]; i-=lowbit(i); } return ans;}int main(){ scanf("%d%d",&n,&m); get(0); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(f[a[i]]) { add(i,1); } } char c[10]; int l,r,val; while(m--) { scanf("\n%s",c); if(c[0]=='c') { scanf("%d%d",&l,&r); printf("%d\n",count(r)-count(l-1)); } else { scanf("%d%d%d",&l,&r,&val); for(int i=l;i<=r;i++) { if(f[a[i]]) { add(i,-1); } a[i]+=val; if(f[a[i]]) { add(i,1); } } } }}

 

转载于:https://www.cnblogs.com/stxy-ferryman/p/8977280.html

你可能感兴趣的文章
MYSQL中的日期转换
查看>>
在线修改Schema
查看>>
【学术篇】SDOI2008 仪仗队
查看>>
5.递归实现,把M元用最少的硬币来凑。不同面值的硬币,有10元,5元,2元,1元。...
查看>>
第6章—渲染web视图—使用Thymeleaf
查看>>
Android动态添加Fragment
查看>>
OGRE粒子系统简介
查看>>
C、C++语言中参数的压栈顺序
查看>>
用jquery实现简单的表单验证
查看>>
自然语言3——官网介绍
查看>>
lucene 搜索学习笔记 - OK
查看>>
Java的垃圾回收
查看>>
java中的与或运算
查看>>
Pycharm连接BitBucket
查看>>
ftp 批量上传文件命令
查看>>
nlog自定义文件名
查看>>
java环境变量配置
查看>>
Mysql中文乱码问题解决
查看>>
make clean指令出现问题
查看>>
巴中故里
查看>>