题意:

2种操作

1 a b k c 在区间[a,b]中的(i-a)%k==0的位置i上的数+c

2 a 查询位置a的值

输出每次查询的值

分析:

开始想到多维的线段树,但比较麻烦,看了题解才知道,用BIT实现区间更新,单点查询,若在区间[a,b]上的数加c

就在a位置加c ,b+1位置加-c 这样在查询时sum(i),(i>=a&&i<=b)就是当前i位置的值

维护多个BIT即可

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 50010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int bit[][][N],a[N],n,m;
int lowbit(int x){
return x&(-x);
}
void add(int i,int j,int x,int d){
while(x<=n){
bit[i][j][x]+=d;
x+=lowbit(x);
}
}
int sum(int i,int j,int x){
int num=;
while(x>){
num+=bit[i][j][x];
x-=lowbit(x);
}
return num;
}
int main()
{
while(~scanf("%d",&n)){
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
scanf("%d",&m);
memset(bit,,sizeof(bit));
int s,e,k,c,op,pos;
while(m--){
scanf("%d",&op);
if(op==){
scanf("%d%d%d%d",&s,&e,&k,&c);
add(k,s%k,s,c);
add(k,s%k,e+,-c);
}
else if(op==){
scanf("%d",&pos);
int total=a[pos];
for(int i=;i<=;++i)
total+=sum(i,pos%i,pos);
printf("%d\n",total);
}
}
}
return ;
}

HDU 4267-A Simple Problem with Integers(多个BIT)的更多相关文章

  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(树状数组区间更新)

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

  3. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

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

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

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

  5. HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)

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

  6. 【HDOJ】4267 A Simple Problem with Integers

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

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

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

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

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

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

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

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

随机推荐

  1. C# 实现:将一个文件夹下的.png图片全部移动到另一个文件夹

    如题,代码如下: using System; using System.IO; public class FileMove { public FileMove() { // TODO: } // co ...

  2. poj 3150 Cellular Automaton

    首先来看一下Sample里的第一组数据.1 2 2 1 2经过一次变换之后就成了5 5 5 5 4它的原理就是a0 a1 a2 a3 a4->(a4+a0+a1) (a0+a1+a2) (a1+ ...

  3. 黑马程序员-C#学习笔记

    ---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ---------------------- C#学习笔记 1..NET/.do ...

  4. 无法解析指定的连接标识符 oracle错误12154

    导出的时候老是报这个错,exp userid=c##yh/yh@MyOracle tables=(stu3) file=d:\e.dmp; 解决了好久,最后都失败了,后来加了127.0.0.1:152 ...

  5. Mysql数据库int(1)和tinyint(1)的区别&&扩展阅读

    转自:http://blog.csdn.net/phpwish/article/details/7845921 今天看项目的数据库结构设计,发现一个奇怪的地方. `xxx_detail`   `del ...

  6. CMake学习(1)---简单程序与库

    cmake是linux平台下重要的工具,可以方便的组织makefile.之前一直在windows平台下进行软件开发,在vs2010的IDE里,只要一点run程序就能跑出结果.但是程序的编译并没有那么简 ...

  7. [从jQuery看JavaScript]-匿名函数与闭包(Anonymous Function and Closure)【转】

    (function(){ //这里忽略jQuery所有实现 })(); 半年前初次接触jQuery的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在看到源码的第一眼,我就迷糊了.为什么只有 ...

  8. Restful api测试插件Swagger-UI

    现在多数的项目开发中,网站和移动端都需要进行数据交互和对接,这少不了使用REST编写API接口这种场景.例如我目前的工作,移动端交由了另一团队开发,不同开发小组之间就需要以规范和文档作为标准和协作基础 ...

  9. Windows下使用Visual Studio 2010编译ffmpeg全过程

    在visual studio 2010中调用ffmpeg http://blog.sina.com.cn/s/blog_4178f4bf01018wqh.html Windows下使用Visual S ...

  10. .net通过获取客户端IP地址反查出用户的计算机名

    这个功能看似很少用到,但又非常实用,看似简单,但又在其中存在很多未知因素造成让人悲痛莫名的负能量... 这是公司内部最近在使用的功能,因为是DHCP,所以有时会根据计算机名做一些统计和权限的设置. 也 ...