HDU 4267 A Simple Problem with Integers 多个树状数组
A Simple Problem with Integers
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4000 Accepted Submission(s): 1243
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.
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
int d[maxn][][];
int a[maxn];
int n;
int lowbit(int x)
{
return x&(-x);
}
void update2(int x,int num,int k,int mod)
{
while(x>)
{
d[x][k][mod]+=num;
x-=lowbit(x);
}
}
int getSum1(int x,int k)
int s=;
while(x<=n)
{
REP_1(i,)
{
s+=d[x][i][k%i];
}
x+=lowbit(x);
}
return s;
} int main()
{
while(RD(n)!=-)
{
REP_1(i,n)
RD(a[i]);
memset(d,,sizeof(d));
int q;
RD(q);
while(q--)
{
int t;
RD(t);
if(t==)
{
int l,r,k,c;
RD(l),RD(r),RD(k),RD(c);
update2(r,c,k,l%k);
update2(l-,-c,k,l%k);
}
if(t==)
{
int c;
RD(c);
printf("%d\n",getSum1(c,c)+a[c]);
}
}
}
}
HDU 4267 A Simple Problem with Integers 多个树状数组的更多相关文章
- HDU 4267 A Simple Problem with Integers
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4267 A Simple Problem with Integers(树状数组区间更新)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers
http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...
- HDU 5293 Tree chain problem 树形dp+dfs序+树状数组+LCA
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形 ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
- HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)
以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- HDU 3468:A Simple Problem with Integers(线段树+延迟标记)
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...
- 【HDOJ】4267 A Simple Problem with Integers
树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
随机推荐
- Python_oldboy_自动化运维之路(八)
本节内容: 列表生成式,迭代器,生成器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 1.列表生成式,迭代器,生成器 1.列表生成式 #[列表生成] #1.列 ...
- C++之插入迭代器
#include<iostream> #include<vector> #include<list> #include<iterator> usingn ...
- Vue select 下拉菜单
1.html <div id="app-8"> <select v-model="selected"> <option v-for ...
- pytest的参数化测试
感觉在单元测试当中可能有用, 但在django这种框架中,用途另一说. import pytest import tasks from tasks import Task def test_add_1 ...
- #JS 异步处理机制的几种方式
Javascript语言的执行环境是"单线程"(single thread,就是指一次只能完成一件任务.如果有多个任务,就必须排队,前面一个任务完成,再执行后面一个任务,以此类推) ...
- 【58沈剑架构系列】互联网公司为啥不使用mysql分区表?
缘起:有个朋友问我分区表在58的应用,我回答不出来,在我印象中,百度.58都没有听说有分区表相关的应用,业内进行一些技术交流的时候也更多的是自己分库分表,而不是使用分区表.于是去网上查了一下,并询问了 ...
- C语言:写一函数,将两个字符串中的元音字母复制到另一个字符串,然后输出
题目描述 写一函数,将两个字符串中的元音字母复制到另一个字符串,然后输出. 输入 一行字符串 输出 顺序输出其中的元音字母(aeiuo) 样例输入 abcde 样例输出 ae 编码: #include ...
- 【51nod】1773 A国的贸易
题解 FWT板子题 可以发现 \(dp[i][u] = \sum_{i = 0}^{N - 1} dp[i - 1][u xor (2^i)] + dp[i - 1][u]\) 然后如果把异或提出来可 ...
- HDU - 4458 计算几何判断点是否在多边形内
思路:将飞机看成不动的,然后枚举时间看点是否在多边形内部. #include<bits/stdc++.h> #define LL long long #define fi first #d ...
- ES6-const注意
注意要点 const 如何做到变量在声明初始化之后不允许改变的?其实 const 其实保证的不是变量的值不变,而是保证变量指向的内存地址所保存的数据不允许改动.此时,你可能已经想到,简单类型和复合类型 ...