标签:
4 1 1 1 1 14 2 1 2 2 2 3 2 4 1 2 3 1 2 2 1 2 2 2 3 2 4 1 1 4 2 1 2 1 2 2 2 3 2 4
1 1 1 1 1 3 3 1 2 3 4 1
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 50010
using namespace std;
int a[N];
int c[N][12][12];
int n,m;
int lowbit(int x) {
return x&(-x);
}
void updata(int x,int k,int mod,int num) {
while(x<=n) {
c[x][k][mod] += num;
x += lowbit(x);
}
}
int getsum(int x,int y) {
int s = 0;
while(x>0) {
for(int i=1; i<=10; i++) {
s += c[x][i][y%i];
}
x -= lowbit(x);
}
return s;
}
int main() {
while(scanf("%d",&n)!=EOF) {
memset(c,0,sizeof(c));
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
int x,y,k,num;
scanf("%d",&m);
while(m--) {
scanf("%d",&x);
if(x == 1) {
scanf("%d%d%d%d",&x,&y,&k,&num);
updata(x,k,x%k,num);
updata(y+1,k,x%k,-num);
} else {
scanf("%d",&y);
int sum = getsum(y,y);
printf("%d\n",sum+a[y]);
}
}
}
return 0;
}
版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。
HDU 4267 A Simple Problem with Integers(树状数组)
标签:
原文地址:http://blog.csdn.net/yeguxin/article/details/47999833