# hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组)

Let A1, A2, ... , AN be N elements. Youneed to deal with two kinds of operations. One type of operation is to add agiven number to a few numbers in a given interval. The other is to query thevalue of some element.

Input

There are a lot of test cases.
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ..., AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i<= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10,-1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)

Output

For each test case, output several lines toanswer all query operations.

const int MAXN = 1000000;
int s[11][11][50005];
int a[50005];
int n;
int lowbit(int x)
{
return x & (-x);
}
int add(int a, int b, int i, int v)
{
while (i <= n)
{
s[a][b][i] += v;
i += lowbit(i);
}
}
int sum(int a, int b, int i)
{
int ret = 0;
while (i > 0)
{
ret += s[a][b][i];
i -= lowbit(i);
}
return ret;
}

int main ()
{
int T;
int op, aa, bb, v, k;
while (RI(n) != EOF)
{
FE(i, 1, n) RI(a[i]);
CLR(s, 0);
int m;
RI(m);
while (m--)
{
RI(op);
if (op == 1)
{
RIV(aa, bb, k, v);
add(k, aa % k, aa, v);
add(k, aa % k, (bb + 1),-v);
}
else
{
RI(aa);
int ans = a[aa];
FE(i, 1, 10) ans += sum(i, aa %i, aa);
cout << ans <<endl;
}
}
}
return 0;
}

• 本文已收录于以下专栏：

## HDU 4267 A Simple Problem with Integers(树状数组)

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 ...
• yeguxin
• 2015年08月26日 10:46
• 596

## 线段树模版—A Simple Problem with Integers

D - A Simple Problem with Integers Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:...
• llzhh
• 2016年04月29日 00:03
• 161

## POJ 3468 A Simple Problem with Integers (树状数组解法 树状数组区间更新 区间查询)

• Forever_wjs
• 2016年07月05日 10:41
• 344

## poj 3468 A Simple Problem with Integers 线段树/树状数组

• xc19952007
• 2016年02月24日 23:44
• 213

## A Simple Problem with Integers+hdu+树状数组

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 ...
• u012870383
• 2014年12月14日 22:20
• 407

## hdu4267--A Simple Problem with Integers（树状数组）

• u013015642
• 2015年08月26日 08:53
• 1264

## HDU - 4267 A Simple Problem with Integers(树状数组)

• L123012013048
• 2015年10月20日 15:50
• 212

## hdu 4267 A Simple Problem with Integers 树状数组

• xc19952007
• 2016年02月27日 20:13
• 208

## HDU 4267 A Simple Problem with Integers --树状数组

• hq572241670
• 2014年11月27日 18:44
• 410

## HDU 4267 A Simple Problem with Integers（树状数组）

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 ...
• acm_BaiHuzi
• 2015年07月13日 12:31
• 561

举报原因： 您举报文章：hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)