HDU5057(分块)
Argestes and Sequence
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1279 Accepted Submission(s): 373
Problem Description
S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).
Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.
Note: The 1st digit of a number is the least significant digit.
Input
For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],...,a[n]—initial value of array elements.
Each of the next M lines begins with a character type.
If type==S,there will be two integers more in the line: X,Y.
If type==Q,there will be four integers more in the line: L R D P.
[Technical Specification]
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=231 - 1
1<=X<=N
0<=Y<=231 - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9
Output
Sample Input
Sample Output
//2016.8.13
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N = ;
int a[N], len = , n, mi[] = {, , , , , , , , , , }; struct node
{
int cnt[][];//cnt[d][p]表示每个块内第d位是p的个数
}block[]; bool judge(int x, int d, int p)//判断x的第d位是否为p
{
return x/mi[d]%==p;
} int query(int l, int r, int d, int p)
{
int id1 = l/len, id2 = r/len, ans = ;
if(id1==id2)//如果l,r在同一个块内,暴力枚举
{
for(int i = l; i <= r; i++)
if(judge(a[i], d, p))
ans++;
}else
{
for(int i = id1+; i <= id2-; i++)//把中间的块加起来
ans+=block[i].cnt[d][p];
for(int i = l; i <= (id1+)*len && i <= n; i++)//暴力最左边的块
if(judge(a[i], d, p))
ans++;
for(int i = id2*len+; i <= r; i++)//暴力最右边的块
if(judge(a[i], d, p))
ans++;
}
return ans;
} void update(int x, int y)
{
int tmp = a[x], id = (x-)/len;//这里起初x少减了个1,WA了好多次忧伤。。。
a[x] = y;
for(int i = ; i <= ; i++)
{
block[id].cnt[i][tmp%]--;
tmp/=;
}
tmp = a[x];
for(int i = ; i <= ; i++)
{
block[id].cnt[i][tmp%]++;
tmp/=;
}
} int main()
{
int T, d, p, m, x, y, l, r, id;
char cmd;
cin>>T;
while(T--)
{
scanf("%d%d", &n, &m);
memset(block, , sizeof(block));
memset(a, , sizeof(a));
for(int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
id = (i-)/len;
int tmp = a[i];
for(int j = ; j <= ; j++)//初始化块
{
block[id].cnt[j][tmp%]++;
tmp/=;
}
}
while(m--)
{
getchar();
scanf("%c", &cmd);
if(cmd == 'Q')
{
int ans = ;
scanf("%d%d%d%d", &l, &r, &d, &p);
ans = query(l, r, d, p);
printf("%d\n", ans);
}else
{
scanf("%d%d", &x, &y);
update(x, y);
}
}
} return ;
}
HDU5057(分块)的更多相关文章
- hdu5057 分块处理,当数值大于数据范围时树状数组 真是巧 将大数据分为小数据来处理
这题说的给了100000个数有100000次操作 询问 L和R 区间内 在D位上为P的个数,用树状数组存 要开[10][10][100000]的int 开不了但是能开 这么大的unsign short ...
- hdu5057 Argestes and Sequence 分块
Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submiss ...
- 【分块】hdu5057 Argestes and Sequence
分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...
- PHP搭建大文件切割分块上传功能
背景 在网站开发中,文件上传是很常见的一个功能.相信很多人都会遇到这种情况,想传一个文件上去,然后网页提示"该文件过大".因为一般情况下,我们都需要对上传的文件大小做限制,防止出现 ...
- POJ2104 K-th Number [分块做法]
传送:主席树做法http://www.cnblogs.com/candy99/p/6160704.html 做那倒带修改的主席树时就发现分块可以做,然后就试了试 思想和教主的魔法差不多,只不过那个是求 ...
- HDU 4467 分块
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4467 题意:给定n个点m条边的无向图,点被染色(黑0/白1),边带边权.然后q个询问.询问分为两种: ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1010 Weak Pair dfs序+分块
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...
- CC countari & 分块+FFT
题意: 求一个序列中顺序的长度为3的等差数列. SOL: 对于这种计数问题都是用个数的卷积来进行统计.然而对于这个题有顺序的限制,不好直接统计,于是竟然可以分块?惊为天人... 考虑分块以后的序列: ...
- bzoj2002弹(dan)飞绵羊 分块水过
据说是道lct求深度的题 但是在小猫大的指点下用分块就n^1.5水过了 = =数据忘记加强系列 代码极其不美观,原因是一开始是听小猫大讲的题意,还以为是弹到最前面... #include <cs ...
随机推荐
- svn代码管理的使用工作流程
1. 新建代码库repository. 2. checkout 到workspace. 3. checkin 回 repository. 4. release 一个版本出来(相当于拉出一个branch ...
- PAT (Advanced Level) 1011. World Cup Betting (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 【GO】关于GO的浅显总结
最近看了下go的入门教程,被它的强大震撼了,第一印象感觉特点主要有如下几个吧: 1. 集c,python,erlang之长,和c同属静态语言,保证效率:语法如python一样简洁,库很强大:从erla ...
- js 各种常用js验证
判断http或者https var http = 'https:' == document.location.protocol ? false : true; js的类型检测方式 /**** js的类 ...
- man info --help区别
--help: 是一个工具选项,可以用来显示一些工具的信息 man : 可以显示系统手册页中的内容,这些内容大多数都是对命令的解释信息 PS: () Space 键可以显示下一屏的文本信息 () q ...
- 关于Discuz与jQuery冲突问题的亲测解决方法
最近的一个项目整合dede和discuz程序,客户要求风格统一,所以有很多样式及特效都是要公用的.其中jQuery库定义的函数$()正好与discuz的comme.js中函数一样,这样就冲突了,导致d ...
- Codeforces Education Round 11
A(模拟+数学) 题意:在一个数列当中最少添加多少个数可以使它们两两互质,并打印出添加以后的数列 #include <iostream> #include <cstdio> # ...
- jquery核心功能分析
作者:zccst 核心功能包括: jQuery是如何定义的,如何调用的,如何扩展的.掌握核心方法是如何实现的,是理解jQuery源码的关键.这里理解了一切豁然开朗. 1,如何定义,即入口 // Def ...
- shell 实例学习
安装crond:yum install crontabs (http://blog.163.com/victory_wxl/blog/static/14130530220115296180333/) ...
- Freemarker入门案例
Freemarker入门案例 首先需要到freemarker官方下载freemarker的jar包,导入到项目中,如:freemarker-2.3.19.jar 1.先建个freemarker的工具类 ...