题意略。

开始想开一个三维的树状数组,但是一算空间不够,正解是离线操作,按位来计算,一共是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. python课堂整理20----生产者消费者模型

    一.实现功能:店铺生产包子,消费者来吃 import time def producter(): ret = [] for i in range(10): time.sleep(0.1) ret.ap ...

  2. mysql 不同版本下 group by 组内排序的差异

    最近发现网上找的 group by 组内排序语句在不同的mysql版本中结果不一样.   建表语句:   SET FOREIGN_KEY_CHECKS=0;   -- ---------------- ...

  3. 使用ASM实现动态代理

    如果对我这段代码感兴趣,直接拷贝测试debug,要不然你不知道我写的是什么鬼,如果有什么问题,可以告诉我. 一.实现动态代理,首先得考虑有应该定义哪些类,根据JDK的动态代理思想,那么它就应该有一个生 ...

  4. Angular JS 中的内置方法之表单验证

    angular js 结合html5 可以实现强大的表单验证功能 关闭html5自带的表单验证功能可以用

  5. python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

    python实现爬虫遇到编码问题: error:UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX ...

  6. 常用GDB命令行调试命令

    po po是print-object的简写,可用来打印所有NSObject对象.使用举例如下: (gdb) po self <LauncherViewController: 0x552c570& ...

  7. bug探索常识

    1.什么是Bug探索测试? 探索测试是将测试设计和测试执行整合在一起,形成的一种测试方法. 2.探索性测试怎么做? 需要认真思考和分析结果,并且在探索测试的过程中做记录. 3.探索性测试的好处? 可以 ...

  8. Iterator-Java

    在Java中,Iterator的作用就是为了方便处理集合中的元素.例如获取和删除集合中的元素. 在JDK8,Iterator接口提供了如下方法: 迭代器Iterator最基本的两个方法是next()和 ...

  9. hashCode和equals的区别

    关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料. 有面试官会问:你重写过 hashcode 和 equals 么,为什么重写equals时必须重写has ...

  10. Go中的字符串使用----strings和strconv

    Go中的字符串操作 字符串是工作中最常用的,值得我们专门的练习一下.在Go中使用strings包来操作字符串,这也是内置的包哈,不像Java中要么手写,要么引入common-lang 或者 别的第三方 ...