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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. using namespace std;
  5. const int N=+;
  6. int aa[N];
  7. int n,m;
  8. int sum[N][][];//开稍大一点就会MLE
  9.  
  10. int lowbit(int x)
  11. {
  12. return x&(-x);
  13. }
  14. void update(int x,int k,int mod,int v)
  15. {
  16. while(x<=n)
  17. {
  18. sum[x][k][mod]+=v;
  19. x+=lowbit(x);
  20. }
  21. }
  22. int query(int x,int y)
  23. {
  24. int res=;
  25. while(x)
  26. {
  27. for(int i=;i<=;i++)
  28. {
  29. res+=sum[x][i][y%i];
  30. }
  31. x-=lowbit(x);
  32. }
  33. return res;
  34. }
  35. int main()
  36. {
  37. while(~scanf("%d",&n))
  38. {
  39. memset(sum,,sizeof(sum));
  40. for(int i=;i<=n;i++)
  41. {
  42. scanf("%d",&aa[i]);
  43. }
  44. scanf("%d",&m);
  45. int op,a,b,k,c;
  46. while(m--)
  47. {
  48. scanf("%d",&op);
  49. if(op==)
  50. {
  51. scanf("%d",&k);
  52. int ans=query(k,k);
  53. printf("%d\n",ans+aa[k]);
  54. }
  55. else if(op==)
  56. {
  57. scanf("%d%d%d%d",&a,&b,&k,&c);
  58. int kk=(b-a)/k;
  59. update(a,k,a%k,c);
  60. update(b+,k,a%k,-c);
  61. }
  62. }
  63. }
  64. return ;
  65. }

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. First commit

    今天是2016年11月14日.天气晴. 第一篇博客,准备在这里记录下我学到的技术,希望能够坚持下来.^.^

  2. windows php swoole 安装

    Cygwin 官方地址:http://www.cygwin.com/ swoole 官方下载地址:https://github.com/swoole/swoole-src/releases 1.下载 ...

  3. Bootstrap 表单

    表单布局 Bootstrap 提供了下列类型的表单布局: 垂直表单(默认) 内联表单 水平表单 垂直或基本表单 基本的表单结构是 Bootstrap 自带的,个别的表单控件自动接收一些全局样式.下面列 ...

  4. IOS常用框架

    IOS开发中有用的第三方库 #Objective-C中最受瞩目库 [链接](https://github.com/languages​​/Objective-C/most_watched) * [th ...

  5. XML 详解

    import urllib import requests from xml.etree import ElementTree as ET root = ET.XML(open('D:\E\seman ...

  6. Android Token的使用学习

    学习Token Token是什么? Token是服务端生成的一串字符串,以作客户端进行请求的一个令牌,当第一次登录后,服务器生成一个Token便将此Token返回给客户端,以后客户端只需带上这个Tok ...

  7. 深入理解JQuery插件开发

    如果你看到这篇文章,我确信你毫无疑问会认为jQuery是一个使用简便的库.jQuery可能使用起来很简单,但是它仍然有一些奇怪的地方,对它基本功能和概念不熟悉的人可能会难以掌握.但是不用担心,我下面已 ...

  8. Python Day 01

    What is variables? 一段命名的内存空间 变量即在程序运行过程中,它的值是允许改变的量 1.变量命名: 合法: 显式.通俗易懂. nums_of_jay_gf = 19 NumsOfJ ...

  9. 嵌入式 python异常except语句用法与引发异常 zz

    http://blog.sina.com.cn/s/blog_8795b0970101dj0a.html

  10. 第九篇.bootstrap导航

    创建一个标签式的导航菜单的步骤是: 在ul标签上加上class  nav 再ul标签上加上 class .nav-tabs. 在li标签上加上 active表示激活该项 <ul class=&q ...