【三维树状数组与离散化】HDU 4267——A Simple Problem with Integers
来源:互联网 发布:java虚拟主机管理系统 编辑:程序博客网 时间:2024/05/17 00:51
题目:点击打开链接
长春赛区网络赛的题,也是2012年五大区网络赛第一场的第一个题,当时智商拙计,连树状数组和线段树的大名也没有听说过,居然以为是模拟被大神们好一阵修理。。
现在学习了树状数组,写起来也是磕磕绊绊,参阅了若干大神的若干资料,终于凑合了这个三维树状数组的更新。和一般的树状数组不同的是,为节约时间,尽量不TLE,我们的第二维是K,第三维是a%k(为什么是这个呢?原式中的(i-a)%k==0可以移向的。。更新的时候也是按照这个余数来跳着更新,忽忽悠悠就这么过了。。。。
//(i-a)%k==0可以换成i%k==a%k,这个思路转自大神blog #include <iostream>#include <stdio.h>#include <string.h>using namespace std;int numpack[60000],N;int c[60000][11][11]; //第二维为k,第三维为mod int lowbit(int x){return x&(-x);}void update_addnum(int pos,int delta,int mod,int k) //修改成三维的 {for(int i=pos;i>0;i-=lowbit(i)){c[i][k][mod]+=delta;}}void update_subnum(int pos,int delta,int mod,int k) //修改成三维的 {for(int i=pos;i>0;i-=lowbit(i)){c[i][k][mod]-=delta;}}int find_add(int x){int a=x;int result=0;for(int i=x;i<=N;i+=lowbit(i)){for(int j=1;j<=10;j++){result+=c[i][j][a%j]; //把第二维遍历一遍 }}return result;}int main(){while(scanf("%d",&N)!=EOF){memset(numpack,0,sizeof(numpack));memset(c,0,sizeof(c));for(int i=1;i<=N;i++){scanf("%d",&numpack[i]);}int opernum,oper,a,b,c,k;scanf("%d",&opernum);while(opernum--){scanf("%d",&oper);if(oper==1){scanf("%d%d%d%d",&a,&b,&k,&c);update_addnum(b,c,a%k,k);update_subnum(a-1,c,a%k,k);}if(oper==2){int idx;scanf("%d",&idx);int res=numpack[idx]+find_add(idx);//更新值加原始值 printf("%d\n",res);}}}return 0;}
- 【三维树状数组与离散化】HDU 4267——A Simple Problem with Integers
- hdu(4267)A Simple Problem with Integers(三维树状数组)
- HDU 4267 A Simple Problem with Integers 数列离散化 + 树状数组
- HDU 4267 A Simple Problem with Integers 树状数组
- HDU 4267 A Simple Problem with Integers --树状数组
- HDU 4267 A Simple Problem with Integers(树状数组)
- HDU 4267 A Simple Problem with Integers(树状数组)
- HDU - 4267 A Simple Problem with Integers(树状数组)
- hdu 4267 A Simple Problem with Integers 树状数组
- HDU-4267-A Simple Problem with Integers-(树状数组)
- HDU4267 A Simple Problem with Integers(树状数组 离散化)
- A Simple Problem with Integers+hdu+树状数组
- HDOJ 4267 A Simple Problem with Integers 树状数组
- hdu 4267 A Simple Problem with Integers 线段树&树状数组
- HDU 4267 - A Simple Problem with Integers 树状数组区间修改
- hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组)
- HDU - 4267 A Simple Problem with Integers(树状数组的逆操作)
- HDU 4267 - A Simple Problem with Integers
- 完全卸载xcode
- allegro使用小技巧备忘录
- 项目2辅助学习练习2
- Java远程方法调用
- 13-01-26-->11
- 【三维树状数组与离散化】HDU 4267——A Simple Problem with Integers
- CFileDialog导致程序崩溃的解决方案
- hadoop下的Kmeans算法实现三
- hdu 2066 一个人的旅行
- poj1236-network of schools(强连通分量)
- java动态代理(JDK和cglib)
- python操作MySQL数据库的方法分享
- C语言和设计模式(继承、封装、多态)
- POJ 1363 Rails 栈的应用