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.op==1,输入四个数据a,b,k,c将区间[a,b]中的数i满足(i-a)%k  == 0加上c.
2.op==2,输入一个数y,输出序列中第y个数的值。

被这题虐哭,(毕竟太弱了~~)关键就是建立多个树状数组,然而我对树状数组理解还是不行啊!

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_树状数组的更多相关文章

  1. A Simple Problem with Integers(树状数组HDU4267)

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

  2. POJ3468 A Simple Problem with Interger [树状数组,差分]

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

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

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

  4. POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问

    今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...

  5. luogu 2519 [HAOI2011]problem a 动态规划+树状数组

    发现每一次 $[b[i]+1,n-a[i]]$ 这个区间的分数必须相同,否则不合法. 而一个相同的区间 $[l,r]$ 最多只能出现区间长度次. 于是,就得到了一个 $dp:$ 将每一种区间的出现次数 ...

  6. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

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

  7. Poj 3468-A Simple Problem with Integers 线段树,树状数组

    题目:http://poj.org/problem?id=3468   A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  8. A Simple Problem with Integers(100棵树状数组)

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

  9. POJ 3468 A Simple Problem with Integers(树状数组区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97217   ...

随机推荐

  1. Java8新特性——接口的默认方法和类方法

    Java8新增了接口的默认方法和类方法: 以前,接口里的方法要求全部是抽象方法,java8以后允许在接口里定义默认方法和类方法: 不同的是: 默认方法可以通过实现接口的类实例化的对象来调用,而类方法只 ...

  2. MICAPS二次开发一些功能调用

    1.调用地图并将micaps文件加载地图上 IFileBindingService fbs = ServiceLocator.Current.GetInstance< IFileBindingS ...

  3. asp.netajax开发应用心得-accordation控件的事件处理

    今天,再次运行以前的项目时,发现按钮的单击事件不起作用了,加了断点之后发现根本没有触发该事件.... 按照网上找到的答案,有的说把控件删掉重新拖拽一个进去,虽然以前也遇到过控件失效,重新拖拽有效的时候 ...

  4. 5、HTML5列表、块和布局

    1.块元素 块元素在显示的时候,通常会以新行开始 如:<h1> <p> <ul> <!-- 块—>注释 <p>hello</p> ...

  5. RAM清理器

    或许有些氨基小白不知道RAM是什么,官方的解释是"运行内存" 只要你的RAM够大,你玩什么都不卡! 今天给大家带来的就是 <RAM清理器>!!体积小,能量大就是我给他介 ...

  6. 利用WPS 2012/2013 0day针对中国政府部门的定向攻击

    今天早上,我们捕获到一个利用wps 2012/2013 0day针对中国政府部门的钓鱼邮件定向攻击事件. 邮件发件人以2014中国经济形势解析高层报告组委会 标题发出,附件为包含wps2012 0da ...

  7. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

  8. Apriori on MapReduce

    Apiroi算法在Hadoop MapReduce上的实现 输入格式: 一行为一个Bucket 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 ...

  9. XML特殊字符处理

    XML共有5个特殊字符,分别为:&<>"' 如果XML文件中需要包含如上5个特殊字符,有两种方式: 1.将包含特殊字符的字符串放在<![CDATA[]]>中 ...

  10. C#_基础

    1.形参与实参 形参是函数定义时的参数,实参是函数被引用时传给它的参数 2.重载与重写 重载:发生在同一个类中,函数(方法)名相同但参数列表必须不同,返回类型可以不同 重写:发生在继承类之间,子类必须 ...