#include<iostream>
#include<cstdio>
#include<string.h>
#include<string>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll __int64
#define lll unsigned long long
#define MAX 1000009
#define eps 1e-8
#define INF 0xfffffff
#define mod 1000000007
/*
题意:BIT
想法:先枚举范围内的数有多少是幸运数字,然后标记,然后求前缀和。 对于添加的,先去标记,然后加数值,然后再加标记。
*/
using namespace std;
int n,m;
int c[MAX];
int a[MAX];
int op[MAX];//判断数组
int lowbit(int x)
{
return x&(-x);
}
int sum(int x)
{
int ret = 0;
while(x>0)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d)
{
while(x<=n)
{
c[x]+=d;
x+=lowbit(x);
}
}
int main()
{
for(int i = 1;i<=10009;i++)//枚举
{
int tmp = i;
int flag = 0;
while(tmp)
{
int k = tmp%10;
if(k!=4&&k!=7)
{
flag = 1;
break;
}
tmp/=10;
}
if(!flag)
op[i] = 1;
}
int l,r;
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
for(int i = 1;i<=n;i++)
{
scanf("%d",&a[i]);
if(op[a[i]])
add(i,1);
}
while(m--)
{
char str[15];
cin>>str>>l>>r;
if(str[0]=='c')
{
//cout<<sum(r)<<" "<<sum(l)<<endl;
printf("%d\n",sum(r) - sum(l-1));
}
else
{
int d;
scanf("%d",&d);
for(int i = l;i<=r;i++)
{
if(op[a[i]])
{
add(i,-1);//去标记
}
a[i]+=d;//加D
if(op[a[i]])
{
add(i,1);//重新标记
}
}
}
}
}
return 0;
}
#include<cstdio>
#include<string.h>
#include<string>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll __int64
#define lll unsigned long long
#define MAX 1000009
#define eps 1e-8
#define INF 0xfffffff
#define mod 1000000007
/*
题意:BIT
想法:先枚举范围内的数有多少是幸运数字,然后标记,然后求前缀和。 对于添加的,先去标记,然后加数值,然后再加标记。
*/
using namespace std;
int n,m;
int c[MAX];
int a[MAX];
int op[MAX];//判断数组
int lowbit(int x)
{
return x&(-x);
}
int sum(int x)
{
int ret = 0;
while(x>0)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d)
{
while(x<=n)
{
c[x]+=d;
x+=lowbit(x);
}
}
int main()
{
for(int i = 1;i<=10009;i++)//枚举
{
int tmp = i;
int flag = 0;
while(tmp)
{
int k = tmp%10;
if(k!=4&&k!=7)
{
flag = 1;
break;
}
tmp/=10;
}
if(!flag)
op[i] = 1;
}
int l,r;
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
for(int i = 1;i<=n;i++)
{
scanf("%d",&a[i]);
if(op[a[i]])
add(i,1);
}
while(m--)
{
char str[15];
cin>>str>>l>>r;
if(str[0]=='c')
{
//cout<<sum(r)<<" "<<sum(l)<<endl;
printf("%d\n",sum(r) - sum(l-1));
}
else
{
int d;
scanf("%d",&d);
for(int i = l;i<=r;i++)
{
if(op[a[i]])
{
add(i,-1);//去标记
}
a[i]+=d;//加D
if(op[a[i]])
{
add(i,1);//重新标记
}
}
}
}
}
return 0;
}
本文探讨了如何通过枚举和标记技术统计幸运数字,并利用前缀和解决区间操作问题。详细介绍了幸运数字的定义、统计方法及区间查询与更新的实现。
740

被折叠的 条评论
为什么被折叠?



