标签:
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4032 Accepted Submission(s): 1255
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <set> 7 #include <map> 8 #include <string> 9 #include <vector> 10 #include <queue> 11 #include <stack> 12 #include <iomanip> 13 #include <sstream> 14 using namespace std; 15 //#define local 16 typedef long long LL; 17 const int INF=0x4fffffff; 18 const int EXP=1e-5; 19 const int MS=50005; 20 21 int C[11][11][MS]; //C[mod][k][x] 22 int num[MS]; 23 24 int lowbit(int x) 25 { 26 return x&(-x); 27 } 28 29 // 修改区间,单点求职, 树状数组需要逆过来。 30 31 void updata(int mod,int k,int x,int d) 32 { 33 while(x>0) 34 { 35 C[mod][k][x]+=d; 36 x-=lowbit(x); 37 } 38 } 39 40 int getsum(int a,int x) 41 { 42 int res=0; 43 while(x<MS) //x<=n 44 { 45 for(int k=1;k<=10;k++) 46 { 47 res+=C[a%k][k][x]; 48 } 49 x+=lowbit(x); 50 } 51 return res; 52 } 53 54 int main() 55 { 56 #ifdef local 57 freopen("in.txt","r",stdin); 58 freopen("out.txt","w",stdout); 59 #endif // local 60 int n; 61 while(scanf("%d",&n)!=EOF) 62 { 63 for(int i=1;i<=n;i++) 64 scanf("%d",&num[i]); 65 memset(C,0,sizeof(C)); 66 int m; 67 scanf("%d",&m); 68 while(m--) 69 { 70 int op,a,b,k,c; 71 scanf("%d",&op); 72 if(op==1) 73 { 74 scanf("%d%d%d%d",&a,&b,&k,&c); 75 updata(a%k,k,b,c); 76 updata(a%k,k,a-1,-c); 77 } 78 else 79 { 80 scanf("%d",&a); 81 int ans=getsum(a,a); 82 printf("%d\n",ans+num[a]); 83 } 84 } 85 } 86 return 0; 87 }
A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
标签:
原文地址:http://www.cnblogs.com/767355675hutaishi/p/4382470.html