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. 三层架构和MVC

    注:本文章内所有内容都来自互联网,本人主要是起了一个收集的作用 http://www.cnblogs.com/zhhh/archive/2011/06/10/2077519.html 又看到有人在问三 ...

  2. Lua 的数据结构

    1. Arrays: 注意 #(data), # 加上 table名字 == size of data = {}; , do --行 , do --列 data[(y-)*+x] = (y-)*+x; ...

  3. SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  4. JavaScript执行上下文

    变量声明.函数声明为何会提升?js执行时是如何查找变量的?JavaScript中最基本的部分——执行上下文(execution context) 什么是执行上下文? 当JavaScript代码运行,执 ...

  5. java基础知识回顾之---java String final类普通方法的应用之“子串在整串中出现的次数”

    /* * 2 一个子串在整串中出现的次数. * "loveerlovetyloveuiloveoplove" * 思路: * 1,要找的子串是否存在,如果存在获取其出现的位置.这个 ...

  6. SDUT2241计算组合数C(n,m)(组合数)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2241 这个题的代码适应性也挺强,但这个题倒不适 ...

  7. POJ2996Help Me with the Game

    http://poj.org/problem?id=2996 又是一个大模拟题,表示做模拟题做的恶心,这个题主要是对数据的处理,从表格中将数据取出来再进行处理即可. 主要注意的点就是:1.KQRBN五 ...

  8. Rockethon 2015

    A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: ...

  9. AndroidManifest.xml介绍一

    下面是AndroidManifest.xml的简单介绍,直接上图! 一.manifest结点的属性介绍 二.application结点属性介绍 三.activity.intent-filter.use ...

  10. ZipArchive框架的文件压缩和解压

    导入第三方框架ZipArchive之后还要在系统库文件中导入一个如下文件(搜索libz出来的任何一个都可以)   导入的头文件是#import "Main.h" 文件压缩 -(vo ...