题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4267
题目大意:
对一个长度为n(1<=n<=50000)的数列A进行q(1<=q<=50000)次操作.
操作1:给定a,b,k,c四个整数,使得a,b间满足a<=i<=b,且(i-a)%k==0的数加c.
操作2:给定整数a,求A[a].
思路:
区间更新,询问单点,可用树状数组(今天学到,一般的树状数组是单点更新,询问区间,反过来即可).
隔段更新,所以直接用树状树组不行,那么我们可以知道k只有10,所以可以得到更新时有55种情况
1,2,3,4,5......
1,3,5,7,9......
2,4,6,8,10....
1,4,7,10,13...
2,5,9,12,15...
3,6,10,13,16...
.
.
.
10,20,30,40,50...
所以用55个树状数组即可.
代码:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define ull unsigned __int64
#define ll __int64
//#define ll long long
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle l+r>>1
#define INF 0x3F3F3F3F
#define esp (1e-10)
#define MOD 100000007
#define type int
//const double pi=acos(-1.0);
const int M=50000+5;
#define clr(x,c) memset(x,c,sizeof(x))
type min(type x,type y){return x<y? x:y;}
type max(type x,type y){return x>y? x:y;}
void swap(type& x,type& y){type t=x;x=y;y=t;}
int T,cas=0;
int n,m,A[M];
int val[M][10][10];
int getJ(int a,int k){
for(int i=1;i<=k;i++)
if((a-i)%k==0)
return i;
}
int lowbit(int x){return x&-x;}
void update(int x,int c,int i,int j){
for(;x>0;x-=lowbit(x))
val[x][i][j]+=c;
}
int query(int x,int i,int j){
int ret=0;
for(;x<=n;x+=lowbit(x))
ret+=val[x][i][j];
return ret;
}
void run(){
int i,j;
for(i=1;i<=n;i++)
scanf("%d",&A[i]);
clr(val,0);
scanf("%d",&m);
int op,a,b,k,c;
while(m--){
scanf("%d",&op);
if(op==1){
scanf("%d%d%d%d",&a,&b,&k,&c);
j=getJ(a,k);
a=(a-j)/k+1,b=(b-j)/k+1;
update(b,c,k-1,j-1);
if(a>1)
update(a-1,-c,k-1,j-1);
}else{
scanf("%d",&a);
int ret=A[a];
for(i=1;i<=10;i++){
j=getJ(a,i);
ret+=query((a-j)/i+1,i-1,j-1);
}
printf("%d\n",ret);
}
}
}
int main(){
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
//run();
while(~scanf("%d",&n)) run();
//for(scanf("%d",&T),cas=1;cas<=T;cas++) run();
//system("pause");
return 0;
}