zoukankan      html  css  js  c++  java
  • 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 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

     题意:只含有4,7的是lucky numbers,区间加,区间询问区间有多少个lucky numbers;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define esp 0.00000000001
    const int N=1e5+10,M=1e6+10,inf=1e9;
    int good[N];
    int check(int x)
    {
        while(x)
        {
            if(x%10!=4&&x%10!=7)
                return 0;
            x/=10;
        }
        return 1;
    }
    vector<int>v;
    int pos[N];
    char ch[10];
    int flag[60][10010];
    int a[N];
    int add[60];
    #define K 1800
    int main()
    {
        for(int i=1;i<=10000;i++)
        if(check(i))
        {
            good[i]=1;
            v.push_back(i);
        }
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            pos[i]=(i-1)/K+1;
            scanf("%d",&a[i]);
            flag[pos[i]][a[i]]++;
        }
        while(m--)
        {
            int l,r;
            scanf("%s%d%d",ch,&l,&r);
            if(ch[0]=='c')
            {
                int ans=0;
                if(pos[l]==pos[r])
                {
                    for(int i=l;i<=r;i++)
                    {
                        if(good[add[pos[i]]+a[i]])
                        ans++;
                    }
                    printf("%d
    ",ans);
                    continue;
                }
                int L=min(n,pos[l]*K);
                for(int i=l;i<=L;i++)
                {
                    if(good[a[i]+add[pos[i]]])
                        ans++;
                }
                int R=max(1,(pos[r]-1)*K+1);
                for(int i=R;i<=r;i++)
                {
                    if(good[a[i]+add[pos[i]]])
                    ans++;
                }
                for(int j=0;j<v.size();j++)
                for(int i=pos[l]+1;i<pos[r];i++)
                {
                    if(v[j]>=add[i])
                    ans+=flag[i][v[j]-add[i]];
                }
                printf("%d
    ",ans);
            }
            else
            {
                int d;
                scanf("%d",&d);
                if(pos[l]==pos[r])
                {
                    for(int i=l;i<=r;i++)
                    {
                        flag[pos[i]][a[i]]--;
                        a[i]+=d;
                        flag[pos[i]][a[i]]++;
                    }
                    continue;
                }
                int L=min(n,pos[l]*K);
                for(int i=l;i<=L;i++)
                {
                    flag[pos[i]][a[i]]--;
                    a[i]+=d;
                    flag[pos[i]][a[i]]++;
                }
                int R=max(1,(pos[r]-1)*K+1);
                for(int i=R;i<=r;i++)
                {
                    flag[pos[i]][a[i]]--;
                    a[i]+=d;
                    flag[pos[i]][a[i]]++;
                }
                for(int i=pos[l]+1;i<pos[r];i++)
                    add[i]+=d;
            }
        }
        return 0;
    }
  • 相关阅读:
    SpringMVC视图解析器
    JavaEE PO VO BO DTO POJO DAO 整理总结
    Android Studio JNI开发入门教程
    javah的使用
    右键“在此处打开命令行窗口”的一个小秘密
    URL和URI的区别
    自学使用
    Ribbon使用
    Eureka集群搭建
    ssm常见面试题
  • 原文地址:https://www.cnblogs.com/jhz033/p/5984141.html
Copyright © 2011-2022 走看看