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 ...
随机推荐
- jQuery中的attr()和prop()使用
总结:除了checked.seleted这样的属性推荐用prop()外,其他的随意都可以. 原因如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...
- iOS学习基本常识
转发至:http://blog.sina.com.cn/s/blog_9266da3d010184i0.html 1. 了解main函数, UIApplication是初始化程序的核心,它接受4个参 ...
- Salesforce开发者学习笔记之二:Salesforce开发平台应用场景
Salesforce作为一个全方位的CRM系统可以应用于企业中的各个不同部门以取代手工的,耗时的以及低效的业务流程,例如 基于报表的数据管理和分析 基于电子邮件的协同合作 本地的文件共享 各种手工操作 ...
- lpc1768的系统时钟
#define XTAL_FREQ 12000000 #define VECT_TAB_OFFSET 0x0000 void SystemInit(void) { //PLL0时钟配置 LPC_ ...
- FMDB事务的使用
http://blog.csdn.net/qq_29892943/article/details/50541439 首先,说一下事务是什么,比如说我们有一个学生表和一个学生成绩表,而且一个学生对应一个 ...
- FZU 2110 Star
简单暴力题,读入%lld会WA,%I64d能过. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- [vue最新实战] gank客户端(vue2 + vue-router2 + vuex +webpace + es6)新手福利,干货多多
vue-meizi 本项目是基于vue2最新实战项目,是适合新手进阶的绝佳教程.代码简单易懂,注释多多.实现了移动端使用最多的 无限滚动,图片加载,左右滑动,等待.先发布预览版本,后面更多更全的功能和 ...
- Elasticsearch的使用场景深入详解
了解了ES的使用场景,ES的研究.使用.推广才更有价值和意义. 1.场景-:使用Elasticsearch作为主要的后端 传统项目中,搜索引擎是部署在成熟的数据存储的顶部,以提供快速且相关的搜索能力. ...
- C++ 虚基类表指针字节对齐
下面博客转载自别人的,我也是被这个问题坑了快两天了,关于各种虚基类,虚继承,虚函数以及数据成员等引发的一系列内存对齐的问题再次详细描述 先看下面这片代码.在这里我使用了一个空类K,不要被这个东西所迷惑 ...
- java系列--JDBC连接oracle
<oracle开发实战经典><oracle DBA从入门到精通> JDBC连接数据库 JNDI连接池 oracle.jdbc.driver.OracleDriver 其实就是一 ...