标签:
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5402 Accepted Submission(s): 1710
/* 类似的区间更新,但这个区间不是实际意义上的区间而是,i到j满足条件的点更新 这个题和区间更新类似,用另一个数组维护,满足条件的点的前缀和,询问的时候直接用原数组的值加上满足条件的值 */ #include<iostream> #include<stdio.h> #include<string.h> #define lowbit(x) x&(-x) #define N 50010 using namespace std; int c[12][12][N];// int n,q,op; void update(int s1,int s2,int x,int val)//间隔为s1,起点为s2,需要更新的点为x { while(x<=n) { c[s1][s2][x]+=val; x+=lowbit(x); } } int getsum(int s1,int s2,int x) { int s=0; while(x>0) { s+=c[s1][s2][x]; x-=lowbit(x); } return s; } int num[N]; int main() { //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin); while(scanf("%d",&n)!=EOF) { //cout<<n<<endl; memset(c,0,sizeof c); for(int i=0;i<n;i++) scanf("%d",&num[i]); scanf("%d",&q); int x,y,k,val; while(q--) { scanf("%d",&op); if(op==1) { scanf("%d%d%d%d",&x,&y,&k,&val); x--; y--; int knum=(y-x)/k;//需要更新的点的个数 int s1=x%k;//这次更新的起点 update(k,s1,x/k+1,val); update(k,s1,x/k+knum+2,-val); } else if(op==2) { scanf("%d",&x); x--; int cur=num[x]; for(int i=1;i<=10;i++)//遍历的是k的取值 cur+=getsum(i,x%i,x/i+1); printf("%d\n",cur); } } } return 0; }
HDU 4267 A Simple Problem with Integers(树状数组区间更新)
标签:
原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/5890038.html