HDU 4267 A Simple Problem with Integers 多个树状数组
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
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.
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)
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
1
1
1
1
3
3
1
2
3
4
1
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 多个树状数组的更多相关文章
- HDU 4267 A Simple Problem with Integers
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4267 A Simple Problem with Integers(树状数组区间更新)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers
http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...
- HDU 5293 Tree chain problem 树形dp+dfs序+树状数组+LCA
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形 ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
- HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)
以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- HDU 3468:A Simple Problem with Integers(线段树+延迟标记)
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...
- 【HDOJ】4267 A Simple Problem with Integers
树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
随机推荐
- Linux内核Ramdisk(initrd)机制【转】
转自:http://www.cnblogs.com/armlinux/archive/2011/03/30/2396827.html 摘要:对于Linux用户来说,Ramdisk并不陌生,可是为什么需 ...
- aarch64_p1
PEGTL-devel-1.3.1-2.fc26.aarch64.rpm 2017-02-14 08:00 63K fedora Mirroring Project PackageKit-1.1.6- ...
- 2013 NEERC
2013 NEERC Problem A. ASCII Puzzle 题目描述:完成一个拼图. solution 暴搜,但好像挺难打的,但听说因为题目限制比较多,其实很多奇怪的情况都不存在. Prob ...
- Flask小demo---代码统计系统
功能要求: 管理员登录 # 第一天 班级管理 # 第一天 学生管理 # 第一天 学生登录 上传代码(zip文件和.py文件) 查看个人提交记录列表 highchar统计 学生列表上方使用柱状图展示现班 ...
- idea心得
概述 Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intel ...
- 根据经纬度坐标计算距离-python
一.两个坐标之间距离计算 参考链接: python实现 1.Python 根据地址获取经纬度及求距离 2.python利用地图两个点的经纬度计算两点间距离 LBS 球面距离公式 美团app筛选“离我最 ...
- 在 Python 中使用 GDB 来调试 转载
2013/11/01 | Comments 大约一年前,我接触了 Java 中的 Btrace 能够不停机查看线上 JVM 运行情况的特性让我艳羡不已. 另外还有强悍的 jStack 和 jConso ...
- drools7 (二、agenda-group 的使用)
几个关键点: 1. 如果没有指定agenda-group 则默认把所有未指定agenda-group的 rules 都执行一遍 2. 如果指定了agenda-group 使用的时候必须指定该name才 ...
- jquery全面判断是否IE6浏览器
今天在写一个登录回车提交表单的操作时,出现keydown在IE6下不能提交的兼容问题,随之无奈,找到可以使用keyup或者keypress事件时间来兼容所有浏览器,但是呢体验效果很不友好,所以只能委屈 ...
- C++11线程池的实现
什么是线程池 处理大量并发任务,一个请求一个线程来处理请求任务,大量的线程创建和销毁将过多的消耗系统资源,还增加了线程上下文切换开销. 线程池通过在系统中预先创建一定数量的线程,当任务请求到来时从线程 ...