E. Lucky Array

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, 467are 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.

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

题意:给出一组序列然后找出区间lcuk数字的个数。

sl: 线段树树状数组第一时间确定是这个数据结构,剩下的就不会了。

扫了一眼题解发现都是树状数组暴力搞得。时间快的就是线段树加一个优化。

优化: 维护区间内的数字到达一个luck数字的最小距离。要是区间修改之后不能使得最小的距离变为0 那么就直接lazy修改下区间luck距离的最小值。

要是超过了,那么就递归到叶子节点直接修改。 时间复杂度我在研究研究。

  1 // by caonima
  2 // hehe
  3 #include <bits/stdc++.h>
  4 using namespace std;
  5 const int MAX = 1e5+;
  6 int num[MAX<<],Min[MAX<<] ,col[MAX<<],cnt[MAX<<];
  7 int a[MAX],Luck_num[MAX],cur=;
  8 int is_luck[MAX];
  9 char op[];
 10 void dfs(int u) {
 11     if(u>) return ;
 12     is_luck[u]=true;
 13     Luck_num[cur++]=u;
 14 
 15     dfs(u*+);
 16     dfs(u*+);
 17     return ;
 18 }
 19 int check(int x) {
 20     for(int i=;i<cur;i++) {
 21         if(x<Luck_num[i]) return Luck_num[i]-x;
 22     }
 23     return ;
 24 }
 25 void push_up(int o) {
 26     cnt[o]=cnt[o<<]+cnt[o<<|];
 27     Min[o]=min(Min[o<<],Min[o<<|]);
 28 }
 29 void build(int L,int R,int o) {
 30     if(L==R) {
 31         num[o]=a[L]; col[o]=;
 32         if(is_luck[a[L]]) cnt[o]=;
 33         else cnt[o]=;
 34         Min[o]=check(a[L]);
 35         return ;
 36     }
 37     int mid=(L+R)>>;
 38     build(L,mid,o<<);
 39     build(mid+,R,o<<|);
 40     push_up(o);
 41 }
 42 void push_down(int o,int m) {
 43     if(col[o]) {
 44         col[o<<]+=col[o]; col[o<<|]+=col[o];
 45         Min[o<<]-=col[o<<]; Min[o<<|]-=col[o<<|];
 46         cnt[o<<]=cnt[o<<|]=;
 47         col[o]=;
 48     }
 49 }
 50 
 51 int Query(int L,int R,int o,int ls,int rs) {
 52     if(ls<=L&&rs>=R) {
 53         return cnt[o];
 54     }
 55     push_down(o,R-L+);//printf("s");
 56     int mid=(R+L)>>;
 57     int cnt=;
 58     if(ls<=mid) cnt+=Query(L,mid,o<<,ls,rs);
 59     if(rs>mid) cnt+=Query(mid+,R,o<<|,ls,rs);
 60     push_up(o);
 61     return cnt;
 62 }
 63 
 64 void Update(int L,int R,int o,int ls,int rs,int val) {
 65     if(ls<=L&&rs>=R) {
 66         if(L==R) {
 67             num[o]+=col[o]+val;
 68             col[o]=;
 69           //  printf("%d\n",num[o]);
 70             if(is_luck[num[o]]) cnt[o]=;
 71             else cnt[o]=;
 72             Min[o]=check(num[o]);
 73 
 74             return ;
 75         }
 76         if(col[o]+val<Min[o]) {
 77             Min[o]-=(col[o]+val);
 78             col[o]+=val;
 79             cnt[o]=;
 80             return ;
 81         }
 82     }
 83 
 84     push_down(o,R-L+);
 85     int mid=(R+L)>>;
 86     if(ls<=mid)  Update(L,mid,o<<,ls,rs,val);
 87     if(rs>mid) Update(mid+,R,o<<|,ls,rs,val);
 88     push_up(o);
 89     return ;
 90 }
 91 
 92 int main() {
 93     int n,m,ls,rs,v;
 94     dfs(); dfs();
 95     sort(Luck_num,Luck_num+cur);
 96     while(scanf("%d %d",&n,&m)==) {
 97         for(int i=;i<=n;i++) scanf("%d",&a[i]);
 98         build(,n,);
 99         for(int i=;i<=m;i++) {
             scanf("%s",op);
             if(op[]=='c') {
                 scanf("%d %d",&ls,&rs);
                 int ans=Query(,n,,ls,rs);
                 printf("%d\n",ans);
             }
             else {
                 scanf("%d %d %d",&ls,&rs,&v);
                 Update(,n,,ls,rs,v);
             }
         }
     }
     return ;

113 }

Codeforces Beta Round #91 (Div. 1 Only) 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水题100道 第十二题 Codeforces Beta Round #91 (Div. 2 Only) A. Lucky Division (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/122/A题意:判断一个数是否能被一个lucky number整除,一个lucky number是一 ...

  3. Codeforces Beta Round #91 (Div. 2 Only) A. Lucky Division【暴力/判断是不是幸运数字4,7的倍数】

    A. Lucky Division time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  7. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

随机推荐

  1. 规范化创建一个vs2017 Mvc框架项目

    vs2107 + dapper + MiniUi 标准化分层封装使 3.1 规范化创建一个vs2017 Mvc框架项目 此时创建的项目勾选 添加单元测试. 添加一个类库,主要用于实体类操作,类库名称 ...

  2. c语言小项目-使用mysql数据库的图书管理系统

    VS2013通过MySQL方式连接到MySQL MySQL官网上C++的API有两个.一个是很成熟的mysql++,另一个是MySQL Connector/C++,近两年才出的,模仿JDBC做的,封装 ...

  3. CF379F New Year Tree

    题意翻译 你是一个程序猿,现在有一棵新年树(并不是传统的带着叶子的树)--它有四个节点: 1,2,3,4. 其中2,3,4的父亲都是1. 新年里,程序猿们往往会做一些有趣的事情.你则选择以往这棵树上加 ...

  4. C# 访问mongodb数据库

    1.引用四个mongodb动态库MongoDB.Bson.dll,MongoDB.Driver.Core.dll,MongoDB.Driver.dll,MongoDB.Driver.Legacy.dl ...

  5. Entityframework Code First 系列

    总篇, 下面会添加每个小篇的链接. 目录如下: 项目搭建 ……

  6. linux 常用shell命令 ls

    ls:查看文件名和目录,用法:$ ls [选项] 1. $ ls 直接输入ls命令,则列出当前目录下的所有文件和目录,不显示详细信息,如类型,大小,日期权限等. 2. $ ls -l -l 选项,每行 ...

  7. 联想 K5 Pro(L38041)免解锁BL 免rec 保留数据 ROOT Magisk Xposed 救砖 ZUI 5.0.188

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  8. Fiddler——抓包工具的使用

    fiddler安装 pc端安装fiddler,自行从百度下载即可 Fiddler是强大且好用的Web调试工具之一,它能记录客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输 ...

  9. Android Studio 入门 Hello World

    Android Studio 入门 Hello World Gavin要加油 1.5k 6月22日 发布 推荐 1 推荐 收藏 17 收藏,2.1k 浏览 引言 前两天开始学习android开发,本来 ...

  10. CLISTCTRL 获取点击列

    CListCtrl中的HitTest.SubItemHitTest的用法 2HitTest:得到当前鼠标位置的Item 其实关键是要有ScreenToClient这个函数的使用,我先前没有用这个函数, ...