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 ...
随机推荐
- CG之基本光照模型计算公式
在一个基本模型里,一个物体表面的颜色是由放射(emissive).环境反射(ambient).漫反射(diffuse)和镜面反射(specular)等光照作用的总和.每种光照作用取决于表面材质的性质( ...
- 常用HQL集锦
1.根据ID查询某"一个"实体类 方法1: String hql = "From ClassEntity as c where c.id=?"; ClassEn ...
- linux自动启动程序
下面用自启动apache为例: 有两种方法可以让Apache在系统启动时自动启动 1. 在/etc/rc.d/rc.local中增加启动apache的命令,例如:/usr/local/httpd/ ...
- CDOJ 1269 ZhangYu Speech
预处理打表,sum[i][j]表示1.....i这些数字中 j 有几个.然后就很好处理询问了. #include<stdio.h> #include<math.h> #incl ...
- kafka第五篇
架构设计:http://www.linuxeden.com/html/news/20130309/136716_2.html 代码实现consumer 和producer
- 产品需求文档写作方法(三)用例文档(UML用例图、流程图)
在产品和技术领域里都有UML的技能知识,而对于产品人员的UML则更多的是指用例图,也就是我所称呼的用户流程图.在讲PRD文档写作的第二篇文章里,我提到了用户流程图的制作,实际上用户流程图是我在产品规则 ...
- CodeForces 450B Jzzhu and Sequences
矩阵快速幂. 首先得到公式 然后构造矩阵,用矩阵加速 取模函数需要自己写一下,是数论中的取模. #include<cstdio> #include<cstring> #incl ...
- vim中c/c++源码跳转
在使用vim阅读c/c++代码的时候,代码跳转很重要, 在学习redis代码的时候遇到这个问题. 网上查找之后通过实践发现cscope比较好用,可以很方便的实现跳转 1. 安装cscope sudo ...
- 11、手把手教你Extjs5(十一)模块界面的总体设计
上一节中设计了一些模块自定义中用到的要素,为了直观起见,这一节先建立一个模块的主界面.看过我 模块管理常规功能自定义系统的设计与实现 博客的人应该会有所了解了.一个模块的主界面是一个Grid,在其上方 ...
- Android线程之基本用法
一: 在android中有两种实现线程thread的方法: 一种是,扩展java.lang.Thread类 另一种是,实现Runnable接口 二: Thread类代表线程类,它的两个最主要的方法是: ...