A Simple Problem with Integers

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5339    Accepted Submission(s): 1693

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
 
Source
 
 
 
解析:55个树状数组。
 
 
 
#include <cstdio>
#include <cstring>
#define lowbit(x) (x)&(-x) const int MAXN = 50000+5;
int num[MAXN];
int c[MAXN][11][11];
int n; void add(int x, int k, int mod, int val)
{
for(int i = x; i <= n; i += lowbit(i))
c[i][k][mod] += val;
} int sum(int x, int a)
{
int ret = 0;
for(int i = x; i > 0; i -= lowbit(i))
for(int j = 1; j <= 10; ++j)
ret += c[i][j][a%j];
return ret;
} int main()
{
while(~scanf("%d", &n)){
for(int i = 1; i <= n; ++i)
scanf("%d", &num[i]);
memset(c, 0, sizeof(c));
int q, a, b, k, c, op;
scanf("%d", &q);
while(q--){
scanf("%d", &op);
if(op == 1){
scanf("%d%d%d%d", &a, &b, &k, &c);
add(a, k, a%k, c);
add(b+1, k, a%k, -c);
}
else{
scanf("%d", &a);
printf("%d\n", num[a]+sum(a, a));
}
}
}
return 0;
}

  

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

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  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. HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)

    以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...

  5. 【HDOJ】4267 A Simple Problem with Integers

    树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...

  6. HDOJ 4267 A Simple Problem with Integers (线段树)

    题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

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

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

  8. HDU 4267 A Simple Problem with Integers 多个树状数组

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

  9. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

随机推荐

  1. DllImport的具体用法

    现在是更深入地进行探讨的时候了.在对托管代码进行 P/Invoke 调用时,DllImportAttribute 类型扮演着重要的角色.DllImportAttribute 的主要作用是给 CLR 指 ...

  2. HDU1251 统计难题 Trie树

    题目很水,但毕竟是自己第一道的Trie,所以还是发一下吧.Trie的更多的应用慢慢学,AC自动机什么的也慢慢学.... #include<iostream> #include<cst ...

  3. maven 命令备忘

    1. 打包时 不执行测试 mvn package -Dmaven.test.skip=true

  4. Redhat 使用中文安装后更换为英文的设定

    vi /etc/sysconfig/i18n将LANG改为LANG=en_US.UTF-8保存退出,重新reboot

  5. js中鼠标滚轮事件详解

    js中鼠标滚轮事件详解   (以下内容部分内容参考了http://adomas.org/javascript-mouse-wheel/ ) 之前js 仿Photoshop鼠标滚轮控制输入框取值中已使用 ...

  6. sqort函数用法总结

    qsort包含在<stdlib.h>头文件中,此函数根据你给的比较条件进行快速排序,通过指针移动实现排序.排序之后的结果仍然放在原数组中.使用qsort函数必须自己写一个比较函数. 函数原 ...

  7. 【POJ】1084 Square Destroyer

    1. 题目描述由$n \times n, n \in [1, 5]$的正方形由$2 \times n \times (n+1)$根木棍组成,可能已经有些木棍被破坏,求至少还需破坏多少木根,可以使得不存 ...

  8. Codeforces Round #204 (Div. 2) C

    写了一记忆化 TLE了  把double换成long long就过了 double 这么耗时间啊 #include <iostream> #include<cstdio> #i ...

  9. 3D图形渲染管线

    3D图形渲染管线 什么是渲染(Rendering)    渲染简单的理解可能可以是这样:就是将三维物体或三维场景的描述转化为一幅二维图像,生成的二维图像能很好的反应三维物体或三维场景(如图1):    ...

  10. Codeforces 383A - Milking cows

    原题地址:http://codeforces.com/problemset/problem/383/A 题目大意:有 n 头奶牛,全部看着左边或者右边,现在开始给奶牛挤奶,给一头奶牛挤奶时,所有能看到 ...