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. 003_Mac挂载NTFS移动硬盘读取VMware虚拟机文件

    一.Mac 挂载NTFS移动硬盘进行读写操作 (Read-only file system) 注意如下图所示先卸载,然后按照下图的命令进行挂载.然后cd /opt/003_vm/   &&am ...

  2. cocos2d-x 日志...

    cocos2d-x  日志... http://blog.csdn.net/themagickeyjianan/article/details/39008297http://blog.csdn.net ...

  3. 纯css进度条,各种兼容

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD&g ...

  4. maven package exec 及 maven 配置文件详解

    maven package test包下执行test 的配置文件 生成target目录,编译.测试代码,生成测试报告,生成jar/war文件 maven 配置文件详解 http://blog.csdn ...

  5. 题解 UVA10048 【Audiophobia】

    这是一道很神奇的题 什么都不卡,就卡c++11(所以评测时要换成c++). 怎么说呐,其实就是跑一个弗洛依德,求图上两点间最大权值最小的路径,输出最大权值最小. P.S.本题n很小,直接floyd变形 ...

  6. thinkphp调试

    Sql调试

  7. Extjs 代码拾穗

    1.tree grid 添加一行 var rootNode = store.getRootNode(); var newRecord = Ext.create('MatrixDlv',{"s ...

  8. Java之杨辉三角的实现

    今天突然想温习一下Java的基础,想了想就写写杨辉三角吧 1.直接法,利用二维数组 import java.util.Scanner; public class Second { public sta ...

  9. 推荐 远程部署 fabric

    自己写的一个例子: from fabric.api import run, env env.hosts = ['nanjing','hefei','haerbin','lanzhou','taiyua ...

  10. shell实现增加删除Linux系统用户脚本(密码为随机)

    README shell环境下运行脚本,根据需求选择相应的功能. List \t\t create the userlist 这一步是必须执行的,脚本会识别本地当前目录下的文件 Useradd \t\ ...