记录编号 |
156384 |
评测结果 |
AAAAAAAAAAAAAAAAAAAAA |
题目名称 |
[CF 121E] 幸运数列 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
7.554 s |
提交时间 |
2015-04-04 17:43:56 |
内存使用 |
14.42 MiB |
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
#define SetFile(x) ( freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) );
#define getc() getchar()
template<class T>inline void getd(T &x){
char ch = getc();bool neg = false;
while(!isdigit(ch) && ch != '-')ch = getc();
if(ch == '-')ch = getc(), neg = true;
x = ch - '0';
while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 100003, LN[32] = {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,44444};
int A[maxn], N, M, Bsize, Bid[maxn] = {-1}, delt[350], Ncnt[350][10003], Bbegin[350] = {1};
bool isLucky[10003];
inline void init(){
getd(N), getd(M);
Bsize = int(sqrt(N * 5.0));
int i, id, *itA = A + 1, *itB = Bid + 1, cnt = 0;
for(const int *it = LN;*it < 10000;++it)isLucky[*it] = true;
for(i = 1, id = 0;i <= N;++i){
getd(*itA);
if(cnt == Bsize)cnt = 1, Bbegin[++id] = i;
else ++cnt;
*(itB++) = id;
++Ncnt[id][*(itA++)];
}
*itB = id + 1;
}
#ifdef DEBUG
inline void view(){
printf("BlockSize = %d\n", Bsize);
for(int i = 1;i <= N + 1;++i)printf("%d ", Bid[i]);putchar('\n');
for(int i = 1;i <= N;++i)printf("%d ", A[i]);putchar('\n');
for(int i = 0;Bbegin[i];++i)printf("%d ", delt[i]);putchar('\n');
}
#endif
inline void clean(int B){
int l = Bbegin[B], *itA = A + l, d = delt[B], *cnt = Ncnt[B];delt[B] = 0;
while(Bid[l++] == B){--cnt[*itA];*itA += d;++cnt[*(itA++)];}
}
inline void Add(){
static int l, r, d;getd(l), getd(r), getd(d);
int t, *it, *begin = delt + Bid[l-1] + 1, *end = delt + Bid[r+1], *cnt;
if((t = Bid[l]) == Bid[r]){
clean(t);cnt = Ncnt[t];
while(l <= r)--cnt[A[l]], A[l] += d, ++cnt[A[l++]];
return;
}
it = begin;while(it != end)*(it++) += d;
if((t = Bid[l]) == Bid[l-1]){
clean(t);it = Bid + l;cnt = Ncnt[t];
while(*it == t)--cnt[A[l]], A[l] += d, ++it, ++cnt[A[l++]];
}
if((t = Bid[r]) == Bid[r+1]){
clean(t);it = Bid + r;cnt = Ncnt[t];
while(*it == t)--cnt[A[r]], A[r] += d, --it, ++cnt[A[r--]];
}
#ifdef DEBUG
printf("\nAdding>>>>\n");
view();
printf("end.\n");
#endif
}
inline void Query(){
static int l, r;getd(l), getd(r);
int ans = 0, B1 = Bid[l-1] + 1, B2 = Bid[r+1], i, *d;
if((i = Bid[l]) == Bid[r]){
clean(i);
while(l <= r)ans += isLucky[A[l++]];
printf("%d\n", ans);
return;
}
const int *it;
for(i = B1, d = delt + i;i < B2;++i, ++d){
it = LN;while(*it < *d)++it;
while(*it < 10000)ans += Ncnt[i][*(it++) - *d];
}
if(Bid[l] != B1){
clean(Bid[l]);
while(Bid[l] != B1)ans += isLucky[A[l++]];
}
if(Bid[r] == B2){
clean(B2);
while(Bid[r] == B2)ans += isLucky[A[r--]];
}
#ifdef DEBUG
printf("\nQuerying>>>>\n");
view();
printf("end.\n");
#endif
printf("%d\n", ans);
}
inline void work(){
char ch;int m = M;
while(m--){
ch = getchar();while(ch < 'a')ch = getchar();while(getchar() >= 'a');
if(ch == 'a')Add();
else Query();
}
}
int main(){
#ifdef DEBUG
freopen("test.txt", "r", stdin);
#elif !defined ONLINE_JUDGE
SetFile(cf121e);
#endif
init();
work();
#ifdef DEBUG
printf("\n%lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}