标签:
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<stdio.h> #include<string.h> #include<iostream> using namespace std; const int MAXN = 50000+100; int F[12][12][MAXN]; int num[MAXN]; int n; void update(int s,int t,int x,int val) { while(x<=n) { F[s][t][x]+=val; x+=x&-x; } } int query(int s,int t,int x) { int res=0; while(x>0) { res+=F[s][t][x]; x-=x&-x; } return res; } int main() { int m; int op,a,b,k,c; while(scanf("%d",&n)!=EOF) { memset(F,0,sizeof(F)); for(int i=1;i<=n;i++) scanf("%d",&num[i]); scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d",&op); if(op==1) { scanf("%d%d%d%d",&a,&b,&k,&c); int t=a%k; update(k,t,a,c); update(k,t,b+1,-c); } else if(op==2) { int ans=0; scanf("%d",&a); for(int j=1;j<=10;j++) ans+=query(j,a%j,a); printf("%d\n",ans+num[a]); } } } return 0; }
HDU 4267 A Simple Problem with Integers (树状数组)
标签:
原文地址:http://www.cnblogs.com/wangdongkai/p/5747122.html