HDU 4267 A Simple Problem with Integers 多个树状数组
2015-03-12 18:45
405 查看
A Simple Problem with Integers
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4000 Accepted Submission(s): 1243
[align=left][b]Problem Description[/b][/align]
Let
A1, A2, ... , AN be N elements. You need to deal with two kinds of
operations. One type of operation is to add a given number to a few
numbers in a given interval. The other is to query the value of some
element.
[align=left][b]Input[/b][/align]
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)
[align=left][b]Output[/b][/align]
For each test case, output several lines to answer all query operations.
[align=left][b]Sample Input[/b][/align]
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
[align=left][b]Sample Output[/b][/align]
1
1
1
1
1
3
3
1
2
3
4
1
[b]题意[/b]
就是给你n个数,m个操作
操作分为两种
1 a b k c,就是 i属于(a,b)这个区间,而且i必须满足(i-a)%k==0,然后这个数加上c
2 a,问你坐标为a的数的大小是多少
[b]题解[/b]
他是分段求和,分段加,肿么办!
那我们建立N多树状数组就好啦,然后直接区间加加加加!!!
然后就好了
[b]代码[/b]
int d[maxn][12][12]; int a[maxn]; int n; int lowbit(int x) { return x&(-x); } void update2(int x,int num,int k,int mod) { while(x>0) { d[x][k][mod]+=num; x-=lowbit(x); } } int getSum1(int x,int k) int s=0; while(x<=n) { REP_1(i,10) { s+=d[x][i][k%i]; } x+=lowbit(x); } return s; } int main() { while(RD(n)!=-1) { REP_1(i,n) RD(a[i]); memset(d,0,sizeof(d)); int q; RD(q); while(q--) { int t; RD(t); if(t==1) { int l,r,k,c; RD(l),RD(r),RD(k),RD(c); update2(r,c,k,l%k); update2(l-1,-c,k,l%k); } if(t==2) { int c; RD(c); printf("%d\n",getSum1(c,c)+a[c]); } } } }
相关文章推荐
- HDU 4267 A Simple Problem with Integers [树状数组]
- A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
- HDU 4267 A Simple Problem with Integers(树状数组)
- HDU - 4267 A Simple Problem with Integers(树状数组的逆操作)
- HDU - 4267 A Simple Problem with Integers(树状数组)
- HDU 4267 - A Simple Problem with Integers 树状数组区间修改
- HDU 4267 A Simple Problem with Integers【树状数组】
- 【三维树状数组与离散化】HDU 4267——A Simple Problem with Integers
- HDU-4267-A Simple Problem with Integers-(树状数组)
- HDU 4267 A Simple Problem with Integers (树状数组)
- HDU 4267 A Simple Problem with Integers(树状数组)
- hdu 4267 A Simple Problem with Integers(分类别维护多个树状数组)
- HDOJ 4267 A Simple Problem with Integers 树状数组
- A Simple Problem with Integers+hdu+树状数组
- HDU 4267 A Simple Problem with Integers
- hdu 4267 A Simple Problem with Integers 线段树,区间部分更新
- poj 3468 A Simple Problem with Integers (线段树区间更新 + 树状数组区间更新)
- poj3468--A Simple Problem with Integers(树状数组解法)
- hdu 4267 A Simple Problem with Integers(线段树)
- HDU 4267 A Simple Problem with Integers