HDU 4267 A Simple Problem with Integers(树状数组)
来源:互联网 发布:net.aspx开发 json 编辑:程序博客网 时间:2024/05/29 09:51
A Simple Problem with Integers
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4191 Accepted Submission(s): 1309
Problem Description
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.
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)
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 to answer all query operations.
Sample Input
4 1 1 1 1142 12 22 32 41 2 3 1 22 1 2 22 32 41 1 4 2 12 12 22 32 4
Sample Output
111113312341
Source
2012 ACM/ICPC Asia Regional Changchun Online
Recommend
liuyiding | We have carefully selected several similar problems for you: 4276 4274 4273 4272 4270
题目:给出n个数,每次将一段区间内满足(i-l)%k==0 (r>=i>=l) 的数ai增加c
题解:可以建55个树状数组,bit[k][i][j]: i=a%k,j表示这个树状数组的第j个数。
求和的话就是10棵树的总和,更新只要更新一颗就行了。
#include<cstring>#include<cstdio>#include<iostream>#include<cstdlib>#include<algorithm>#include<cmath>#define N 50020#define ll long longusing namespace std;int n,a,b,k,v;int bit[11][11][N],num[N];void add(int i,int j,int x,int v) { while(x<=n) { bit[i][j][x]+=v; x+=x&-x; }}int getsum(int i,int j,int x) { int s=0; while(x>0) { s+=bit[i][j][x]; x-=x&-x; } return s;}int main() { //freopen("test.in","r",stdin); while(cin>>n) { for(int i=1; i<=n; i++) scanf("%d",&num[i]); memset(bit,0,sizeof bit); int q; cin>>q; int op; while(q--) { scanf("%d%d",&op,&a); int ans=num[a]; a--; if(op==2) { for(int i=1; i<=10; i++) { ans+=getsum(i,a%i,a/i+1); } printf("%d\n",ans); continue; } scanf("%d%d%d",&b,&k,&v); b--; add(k,a%k,a/k+1,v); add(k,a%k,a/k+(b-a)/k+1+1,-v); } } return 0;}
0 0
- 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(树状数组的逆操作)
- A Simple Problem with Integers+hdu+树状数组
- HDOJ 4267 A Simple Problem with Integers 树状数组
- poj3468--A Simple Problem with Integers(树状数组解法)
- hdu4267--A Simple Problem with Integers(树状数组)
- POJ 3468 A Simple Problem with Integers (树状数组)
- POJ 3468 A Simple Problem with Integers(树状数组)
- A Simple Problem with Integers(线段树-树状数组)
- HDU 4267 A Simple Problem with Integers 数列离散化 + 树状数组
- 【三维树状数组与离散化】HDU 4267——A Simple Problem with Integers
- 1
- [leetcode-231]power of two(C语言)
- 分类算法中的ROC与PR指标
- 进程与线程的一个简单解释
- Android studio导入第三方类库的方法
- HDU 4267 A Simple Problem with Integers(树状数组)
- Android Handler 异步消息处理机制的妙用 创建强大的图片加载类
- 未能加载文件或程序集“OSCommunicationLib”或它的某一个依赖项。试图加载格式不正确的程序。
- java JVM设置
- Java中的类加载器(ClassLoader)及类的加载机制
- 五分钟理解一致性哈希算法(consistent hashing)
- SPOJ QTREE4 lct
- xunsearch使用namespace后bug修复
- 2