题意略。

开始想开一个三维的树状数组,但是一算空间不够,正解是离线操作,按位来计算,一共是10位,所以总共是扫10遍,第i遍只处理第i位的询问,

注意在修改后,要把当前这个位的值存下来(这就是cur数组的作用)!

#include<bits/stdc++.h>
#define maxn 100005
using namespace std; struct op{
int kind,l,r,d,p,x,y;
}; int BIT[][maxn];
int a[maxn],T,N,M,tens[],cur[maxn];
int ans[maxn];
char comd[];
op store[maxn]; int lowbit(int k){
return k & -k;
}
void add(int digit,int pos,int val){
while(pos <= N){
BIT[digit][pos] += val;
pos += lowbit(pos);
}
}
int sum(int digit,int pos){
int ret = ;
while(pos > ){
ret += BIT[digit][pos];
pos -= lowbit(pos);
}
return ret;
} int main(){
tens[] = ;
for(int i = ;i < ;++i) tens[i] = tens[i - ] * ;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M);
memset(ans,-,sizeof(ans));
for(int i = ;i <= N;++i) scanf("%d",&a[i]);
for(int i = ;i < M;++i){
scanf("%s",comd);
if(comd[] == 'Q'){
store[i].kind = ;
scanf("%d%d%d%d",&store[i].l,&store[i].r,&store[i].d,&store[i].p);
}
else{
store[i].kind = ;
scanf("%d%d",&store[i].x,&store[i].y);
}
}
for(int i = ;i <= ;++i){
memset(BIT,,sizeof(BIT));
for(int j = ;j <= N;++j){
add(a[j] % ,j,);
cur[j] = a[j] % ;
}
for(int j = ;j < M;++j){
//printf("------\n");
if(store[j].kind == && store[j].d == i){
ans[j] = sum(store[j].p,store[j].r) - sum(store[j].p,store[j].l - );
}
else if(store[j].kind == ){
int x = store[j].x,y = store[j].y;
add(cur[x],x,-);
add((y / tens[i - ]) % ,x,);
cur[x] = (y / tens[i - ]) % ;
}
}
for(int j = ;j <= N;++j) a[j] /= ;
}
for(int i = ;i < M;++i){
if(ans[i] == -) continue;
printf("%d\n",ans[i]);
}
}
return ;
} /*
3
7 7
101 123 132 456 78 9 1001
Q 1 4 3 4
Q 1 7 2 0
S 1 401
Q 1 4 3 4
Q 1 7 1 1
S 6 999
Q 1 7 3 1 5 7
10 11 12 13 14
Q 1 5 2 1
Q 1 5 1 0
Q 1 5 1 1
Q 1 5 3 0
Q 1 5 3 1
S 1 100
Q 1 5 3 1 6 5
2147483647 2147483647 2147483647 2147483647 2147483647 2147483647
Q 1 5 1 7
Q 2 6 10 2
S 6 0
Q 1 7 1 0
Q 1 7 2 0
*/

HDU 5057的更多相关文章

  1. hdu 5057 Argestes and Sequence(分块算法)

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 5057 Argestes and Sequence --树状数组(卡内存)

    题意:给n个数字,每次两种操作: 1.修改第x个数字为y. 2.查询[L,R]区间内第D位为P的数有多少个. 解法:这题当时被卡内存了,后来看了下别人代码发现可以用unsigned short神奇卡过 ...

  3. hdu 5057 Argestes and Sequence

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. hdu 5057 Argestes and Sequence (数状数组+离线处理)

    题意: 给N个数.a[1]....a[N]. M种操作: S X Y:令a[X]=Y Q L R D P:查询a[L]...a[R]中满足第D位上数字为P的数的个数 数据范围: 1<=T< ...

  5. [kmp+dp] hdu 4628 Pieces

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4622 Reincarnation Time Limit: 6000/3000 MS (Java/Ot ...

  6. hdu 5055(坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Vue的基本使用(二)

    1.数据的双向绑定 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  2. C#读取Modbus数据

    最近在做采集的一些任务所以学了一下Modbus通信,学了好几天昨天终于把大概弄明白了,其实简单来说就是客户端向设备发送一个请求报文请求数据,服务器端根据请求报文向客户端端回发一个报文,客户端在接收到响 ...

  3. TP框架基础 (二) ---空控制器和空操作

    通过之前的学习我们知道了index.php是一个入口文件,如果没有这个入口文件的话,我们需要自己创建! [视图模板文件创建] 视图模板文件存放发位置在: 里面没有模板文件 如果我们想要访问Login控 ...

  4. 如何使用 nvm-windows 管理 nodejs 版本

    写在前边的话: (1). 路径一定不要包含空格,如 Program Files 这样,所以有把程序安装到 D:\Program Files 文件下的同学请注意了:(2). 为了避免 nvm 无法切换源 ...

  5. Kotlin学习快速入门(5)——空安全

    介绍 kotlin中,对象可分为两种类型,可为空的对象和不可为空对象 默认为不可为空对象,代码检测如果发现不可为空对象赋予了null,则会标红报错. 可为空的对象,如果调用了方法,代码检测也会标红报错 ...

  6. tab选项卡代码

    $('.case_header ul li').click(function(){ $(this).addClass('active').siblings().removeClass('active' ...

  7. Chrome谷歌浏览器实用插件

    总结整理了一下个人平时常用的谷歌浏览器插件 Adblock Plus 广告拦截  uBlock Origin Chrono 下载管理器 Tampermonkey 油猴子(各种强大的脚本,强烈推荐) F ...

  8. 夯实Java基础(十三)——字符串

    字符串应该是我们在Java中用的最频繁.最多的,可见字符串对于我们来说是多么的重要,所以我们非常有必要去深入的了解一下. 1.String String就代表字符串,在Java中字符串属于对象.我们刚 ...

  9. windwos环境下安装python2和python3

    一 python安装 下载地址: https://www.python.org/downloads/ 环境变量:Path中添加C:\Python27\Scripts\;C:\Python27\; C: ...

  10. Spark 系列(十四)—— Spark Streaming 基本操作

    一.案例引入 这里先引入一个基本的案例来演示流的创建:获取指定端口上的数据并进行词频统计.项目依赖和代码实现如下: <dependency> <groupId>org.apac ...