Codeforces 122G Lucky Array (a tree-like array with an insane face)

Source: Internet
Author: User

Petya loves lucky numbers. Everybody knows that lucky numbers is positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers, 744, 4 is lucky and 5, +, 467 is not.

Petya have an array consisting of n numbers. He wants to perform m operations of types:

add L r d-add an integer d to all elements whose indexes belong to the Interva L from L to R, inclusive (1≤l≤r≤n, 1≤d≤104);
count L R-find and print on the screens how many lucky numbers there is among Elements with indexes, belong to the interval from L to r inclusive (1≤l≤r≤n). Each lucky number should is counted as many times as it appears in the interval.
Petya have a list of all operations. The operations is such that after all additions the array won ' t has numbers that would exceed 104. Help Petya write a program that would perform these operations.

Input
The first line contains-integers n and M (1≤n, m≤105)-the number of numbers in the array and the number of opera tions correspondingly. The second line contains n positive integers, none of the which exceeds 104-those is the array numbers. Next m lines contain operations, one per line. They correspond to the description given in the statement.

It is guaranteed, then all operations be fulfilled each number in the array would 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 Corr Esponding 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
Count 1 4
Output
4
4
4
Note
In the first sample after the first addition the array would 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

Test instructions

Give a sequence, two operations

1. Interval Plus

2, the number of interval statistics only consists of 4 and 7.

Ensure that each number does not exceed 10000

Exercises

There's nothing to talk about, so I'm going to neta a little bit about the way I'm writing this problem.

First see test instructions, emmm,10000 look very can do ah ...

After a while, WOC, what the hell? This thing can be modified in intervals?

Half an hour ...

WOC, I won't.

One hours ...

Crazy ing

1.5 hours

Forget it, broken broken falls, I wrote a tree-like array to modify the change to replace the interval to see if you can get stuck ...

While writing and thinking

Naive,div1 e is so easy to water past?

And then......

Sorry, a tree-like array can really do whatever it wants.

Emmm, God problem, RBQ,RBQ, very, very, very, very, farewell!

Why don't you show me this when my pants are off?

Forget it, let's go, the code is as follows:

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;inta[100010],f[100010],sum[100010],n,m;void Get(intNow ) {    if(now*Ten+7<=10000) {F[now*Ten+7]=1; Get(now*Ten+7); }    if(now*Ten+4<=10000) {F[now*Ten+4]=1; Get(now*Ten+4); }}intLowbit (intx) {    return(-X) &x;}voidAddintIintval) {     while(i<=N) {Sum[i]+=Val; I+=lowbit (i); }}intCountinti) {    intans=0;  while(i>0) {ans+=Sum[i]; I-=lowbit (i); }    returnans;}intMain () {scanf ("%d%d",&n,&m); Get(0);  for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); if(F[a[i]]) {Add (I,1); }    }    Charc[Ten]; intL,r,val;  while(m--) {scanf ("\n%s", c); if(c[0]=='C') {scanf ("%d%d",&l,&R); printf ("%d\n", COUNT (R)-count (l1)); }        Else{scanf ("%d%d%d",&l,&r,&val);  for(inti=l;i<=r;i++)            {                if(F[a[i]]) {Add (I,-1); } A[i]+=Val; if(F[a[i]]) {Add (I,1); }            }        }    }}

Codeforces 122G Lucky Array (a tree-like array with an insane face)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.