记录编号 274749 评测结果 AAAAAAAAAAAAAAAAAAAAW
题目名称 [CF 121E] 幸运数列 最终得分 95
用户昵称 GravatarMarvolo 是否通过 未通过
代码语言 C++ 运行时间 9.123 s
提交时间 2016-06-29 16:41:22 内存使用 2.62 MiB
显示代码纯文本
#include<cstdio>
using namespace std;

int i,n,m,t;
char c;
int a[200010],p[200010],s[200010];
int bc[50]={0,4,7,44,47,74,77,444,447,474,477,744,747,774,777,4444,4447,4474,
			4477,4744,4747,4774,4777,7444,7447,7474,7477,7744,7747,7774,7777,};
int hash[10010]={0};

inline int read(){
	char x;	int p=0;
	x=getchar();
	while (x<48||x>57) x=getchar();
	while (x>=48&&x<=57)	p=p*10+x-48,x=getchar();
	return p;
}

inline void ready(){
	int i,bh=0,q=0;
	for (i=0;i<=31;i++)	hash[bc[i]]=1;
	for (i=1;i<=n;i++){
		bh=0;
		if (!hash[s[i]])	bh=1;
		if (bh==0){
			p[i]=q=1;	t=i;
			while (t<=n){a[t]+=q;	t+=t&(-t);}
		}
	}
	return;
}

inline void add(){
	int i,l=0,r=0,sum=0,bh=0,q=0;
	l=read();	r=read();	sum=read();
	for (i=l;i<=r;i++){
		s[i]+=sum;	bh=0;   //暴力出奇迹!!! 
		if (!hash[s[i]])	bh=1;
		if (bh==p[i]){
			if (bh==0)	p[i]=q=1;	else q=-1,p[i]=0;
			t=i;
			while (t<=n){a[t]+=q;	t+=t&(-t);}
		}   //说明现状态和原状态不同,维护树状数组 
	}
	return;
}

inline void query(){
	int x=0,y=0,sx=0,sy=0;
	x=read();	y=read();
	t=x-1;
	while (t!=0)	{sx+=a[t];	t-=t&(-t);}
	t=y;
	while (t!=0)	{sy+=a[t];	t-=t&(-t);}
	printf("%d\n",sy-sx);   //树状数组求区间和 
	return;
}

int main(){
	freopen("cf121e.in","r",stdin);
	freopen("cf121e.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)	s[i]=read();
	ready();
	for (i=1;i<=m;i++){
		c=getchar();	while (c==10)	c=getchar();
		if (c=='a')	add();	else query();	
	}
	return 0;
}