Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array 分块
4 seconds
256 megabytes
standard input
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.
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.
For each operation of the second type print the single number on the single line — the number of lucky numbers in the corresponding interval.
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
1
0
1
1
4 5
4 4 4 4
count 1 4
add 1 4 3
count 1 4
add 2 3 40
count 1 4
4
4
4
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+,M=1e6+,inf=1e9;
int good[N];
int check(int x)
{
while(x)
{
if(x%!=&&x%!=)
return ;
x/=;
}
return ;
}
vector<int>v;
int pos[N];
char ch[];
int flag[][];
int a[N];
int add[];
#define K 1800
int main()
{
for(int i=;i<=;i++)
if(check(i))
{
good[i]=;
v.push_back(i);
}
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
pos[i]=(i-)/K+;
scanf("%d",&a[i]);
flag[pos[i]][a[i]]++;
}
while(m--)
{
int l,r;
scanf("%s%d%d",ch,&l,&r);
if(ch[]=='c')
{
int ans=;
if(pos[l]==pos[r])
{
for(int i=l;i<=r;i++)
{
if(good[add[pos[i]]+a[i]])
ans++;
}
printf("%d\n",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(,(pos[r]-)*K+);
for(int i=R;i<=r;i++)
{
if(good[a[i]+add[pos[i]]])
ans++;
}
for(int j=;j<v.size();j++)
for(int i=pos[l]+;i<pos[r];i++)
{
if(v[j]>=add[i])
ans+=flag[i][v[j]-add[i]];
}
printf("%d\n",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(,(pos[r]-)*K+);
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]+;i<pos[r];i++)
add[i]+=d;
}
}
return ;
}
Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array 分块的更多相关文章
- 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 ...
- 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是一 ...
- 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 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
随机推荐
- 【python cookbook】【字符串与文本】3.利用shell通配符做字符串匹配
问题:当工作在Linux shell下时,使用常见的通配符模式(即,*.py.Dat[0-9]*.csv等)来对文本做匹配 解决方案:fnmatch模块提供的两个函数fnmatch().fnmatch ...
- 161208、Java enum 枚举还可以这么用
在大部分编程语言中,枚举类型都会是一种常用而又必不可少的数据类型,Java中当然也不会例外.然而,Java中的Enum枚举类型却有着许多你意想不到的用法,下面让我们一起来看看. 先来看一段代码示例: ...
- java多线程中的生产者与消费者之等待唤醒机制@Version2.0
二.生产者消费者模式的学生类成员变量生产与消费demo, @Version2.0 在学生类中添加同步方法:synchronized get()消费者,synchronized set()生产者 最终版 ...
- Hadoop集群管理之内存管理
1.内存 Hadoop为各个守护进程(namenode,secondarynamenode,jobtracker,datanode,tasktracker)统一分配的内存在hadoop-env.sh中 ...
- mongo 学习笔记
mysql语句 : ' ,,),(,,) mongo语句: db.}}).limit() db."}) db.}}) 条件操作符1 mongodb中的条件操作符有: (>) 大于 ...
- C#:反射
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- SDUT 2411:Pixel density
Pixel density Time Limit: 1000MS Memory limit: 65536K 题目描述 Pixels per inch (PPI) or pixel density is ...
- JAVA基础知识之Queue集合
Queue接口 PriorityQueue类 Deque与ArrayDeque LinkedList 各种线性表性能分析 Queue接口 Queue用来模拟队列这种数据结构,遵循先进先出原则(FIFO ...
- UVa(11292),贪心水题
蓝书P1, 很简单的一个贪心选择,用能力小的去砍小的.本来想双重循环,哎,傻逼了,直接遍历选手,碰到能砍的就砍掉. #include <stdio.h> #include <algo ...
- LInux ugo权限详解[修]
Linux 中的用户和组是用来控制使用者或者进程可以或者不可以使用哪些资源和硬件,是Linux权限控制最基本的方式. 用户和组可以看一下上一章的部分,先来看一下权限. 一.权限概览 在Linux下,使 ...