A Simple Problem with Integers_树状数组
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
【题意】给出n个数,再给出m个操作
被这题虐哭,(毕竟太弱了~~)关键就是建立多个树状数组,然而我对树状数组理解还是不行啊!
sum[x][k][x%k]代表x对k取余的值,然后每次更新树状数组的时候只需要更新update(a,.....) 与update(b+1,.....);
参考资料:http://blog.csdn.net/yeguxin/article/details/47999833
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=+;
int aa[N];
int n,m;
int sum[N][][];//开稍大一点就会MLE int lowbit(int x)
{
return x&(-x);
}
void update(int x,int k,int mod,int v)
{
while(x<=n)
{
sum[x][k][mod]+=v;
x+=lowbit(x);
}
}
int query(int x,int y)
{
int res=;
while(x)
{
for(int i=;i<=;i++)
{
res+=sum[x][i][y%i];
}
x-=lowbit(x);
}
return res;
}
int main()
{
while(~scanf("%d",&n))
{
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++)
{
scanf("%d",&aa[i]);
}
scanf("%d",&m);
int op,a,b,k,c;
while(m--)
{
scanf("%d",&op);
if(op==)
{
scanf("%d",&k);
int ans=query(k,k);
printf("%d\n",ans+aa[k]);
}
else if(op==)
{
scanf("%d%d%d%d",&a,&b,&k,&c);
int kk=(b-a)/k;
update(a,k,a%k,c);
update(b+,k,a%k,-c);
}
}
}
return ;
}
A Simple Problem with Integers_树状数组的更多相关文章
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- POJ3468 A Simple Problem with Interger [树状数组,差分]
题目传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 1 ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
- POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问
今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...
- luogu 2519 [HAOI2011]problem a 动态规划+树状数组
发现每一次 $[b[i]+1,n-a[i]]$ 这个区间的分数必须相同,否则不合法. 而一个相同的区间 $[l,r]$ 最多只能出现区间长度次. 于是,就得到了一个 $dp:$ 将每一种区间的出现次数 ...
- A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- Poj 3468-A Simple Problem with Integers 线段树,树状数组
题目:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- A Simple Problem with Integers(100棵树状数组)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- POJ 3468 A Simple Problem with Integers(树状数组区间更新)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 97217 ...
随机推荐
- WordPress网站搭建
. 1.进入 var/www/html中放入里的文件 2.. 安装http php php-sql [root@jw38 yum.repos.d]# systemctl restart httpd.s ...
- angularjs的一些坑关于 $sec
今天遇到$sec的问题 app.filter('to_trusted', ['$sce', function ($sce) { return function (text) { return $sce ...
- ElasticSearch配置说明
配置文件位于%ES_HOME%/config/elasticsearch.yml文件中. cluster.name: elasticsearch 配置集群名称,默认elasticsearch node ...
- WEB安全性测试
SQL注入 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意)的SQL命令 ...
- Could not parse mapping document from input stream
无法从输入流解析映射文档 1.定义的类名或属性名不对,如:*.hbm.xml文件中属性name对应的实体类name不一致.2.xml头文件中"http://www.hibernate.org ...
- The hierarchy of the type is inconsistent错误问题
在springMVC的AOP 面向切面编程中,引用: package com.ah.aop; import java.lang.reflect.Method; import org.springfra ...
- Ubuntu安装node
#!/bin/bash echo "添加环境变量需要root权限,如无root权限,则不添加环境变量" echo "输入Node下载地址(目前仅支持Node官方网站上Li ...
- 'scrapyd-deploy' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
在windows上使用scrapyd-client 安装后,并不能使用相应的命令'scrapyd-deploy' 需要在"C:\Python27\Scripts" 目录下 增加sc ...
- RHEL6.6 PXE安装-基于VMWare WorkStation
///////////第一部分:安装安装服务器 1.先安装一台RHEL6.6的服务器A(地址为192.168.139.132),作为安装服务器.这样后面的机器就可以指向这台服务器进行自动安装 2.在A ...
- Y+的查看及FLUENT壁面函数的选择
y+的查看 其实,我们关心的应该是壁面y+值.那么我们看云图的话,是可以直接看到的,但是个人感觉,如果case大的话,也不是很方便.此外,你要是看云图的话,要用filled的方式,而且把node va ...