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

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)
 
Output
For each test case, output several lines to answer all query operations.
 
Sample Input
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
 
Sample Output
1
1
1
1
1
3
3
1
2
3
4
1
 
 
题意
就是给你n个数,m个操作
操作分为两种
1 a b k c,就是 i属于(a,b)这个区间,而且i必须满足(i-a)%k==0,然后这个数加上c
2 a,问你坐标为a的数的大小是多少
 
 
题解
他是分段求和,分段加,肿么办!
那我们建立N多树状数组就好啦,然后直接区间加加加加!!!
然后就好了
 
代码
int d[maxn][][];
int a[maxn];
int n;
int lowbit(int x)
{
return x&(-x);
}
void update2(int x,int num,int k,int mod)
{
while(x>)
{
d[x][k][mod]+=num;
x-=lowbit(x);
}
}
int getSum1(int x,int k)
int s=;
while(x<=n)
{
REP_1(i,)
{
s+=d[x][i][k%i];
}
x+=lowbit(x);
}
return s;
} int main()
{
while(RD(n)!=-)
{
REP_1(i,n)
RD(a[i]);
memset(d,,sizeof(d));
int q;
RD(q);
while(q--)
{
int t;
RD(t);
if(t==)
{
int l,r,k,c;
RD(l),RD(r),RD(k),RD(c);
update2(r,c,k,l%k);
update2(l-,-c,k,l%k);
}
if(t==)
{
int c;
RD(c);
printf("%d\n",getSum1(c,c)+a[c]);
}
}
}
}

HDU 4267 A Simple Problem with Integers 多个树状数组的更多相关文章

  1. HDU 4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  2. HDU 4267 A Simple Problem with Integers(树状数组区间更新)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  4. HDU 5293 Tree chain problem 树形dp+dfs序+树状数组+LCA

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形 ...

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

    题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val  操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...

  6. HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)

    以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...

  7. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  8. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

  9. 【HDOJ】4267 A Simple Problem with Integers

    树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...

  10. POJ 3468 A Simple Problem with Integers(线段树/区间更新)

    题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS     Memory Limit: 131072K Description Yo ...

随机推荐

  1. Ubuntu server 搭建Git server【转】

    转自:http://www.cnblogs.com/candle806/p/4064610.html Ubuntu server 搭建Git server,git相比svn,最主要就是分布式了,每个客 ...

  2. C# 链接webservice报错

    未处理 System.ServiceModel.EndpointNotFoundException  Message="没有终结点对可能接受消息的 http://192.168.0.168/ ...

  3. ajax代码示例

    function loadXMLDoc(idName,url,sendOut) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, ...

  4. TCP协议端口状态说明:CLOSE-WAIT、TIME-WAIT 、LISTENING、SYN_SENT、ESTABLISHED、LAST-ACK ...

    了解TCP协议端口的连接状态,对排除和定位网络或系统故障会有很大帮助,因此了解一下是有必要的: 一.LISTENING  提供某种服务,侦听远方TCP端口的连接请求,当提供的服务没有被连接时,处于LI ...

  5. 栈应用之 背包问题(Python 版)

    栈应用之 背包问题 背包问题描述:一个背包里可以放入重量为weight的物品,现有n件物品的集合s,其中物品的重量为别为w0,w1,...,wn-1.问题是能否从中选出若干件物品,其重量之和正好等于w ...

  6. 打开mvc项目无法运行,报"Unable to launch the IIS Express Web server"

    今天遇到一个问题,打开asp.net mvc 项目,右击浏览器运行,无法运行... 提示下面错误, 解决方案: 删除项目文件夹下的 .vs 文件夹,然后重新打开项目运行即可 参考:http://www ...

  7. python基础学习之路No.5 数学函数以及操作

    python的基本数学函数 函数 返回值 ( 描述 ) abs(x) 返回数字的绝对值,如abs(-10) 返回 10 ceil(x) 返回数字的上入整数,如math.ceil(4.1) 返回 5 c ...

  8. MySQL学习笔记:生成时间维度表

    # ---- 对应时间戳怎么生成的? ---- /*TIME_CD TIME_CD1000000 000005000001 000005000002 000005000003 000005000004 ...

  9. Jmeter的接口测试简介

    一.安装Jmeter                                                          Jmeter官方首页:http://jmeter.apache. ...

  10. django model常用字段类型

    摘自 http://www.cnblogs.com/wt869054461/p/4014271.html V=models.AutoField(**options) #int:在Django代码内是自 ...