题意:

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. TDD三个阶段

    TDD的三个阶段 红灯.绿灯.重构 :明确了实施TDD所要遵循的工作流 (需求--->测试-->代码[重构]) 红灯阶段:      为不存在的代码编写测试 绿灯阶段:      仅编写适 ...

  2. 用 EasyBCD 在 Win7/8 中硬盘安装 Ubuntu

    写在前面: 1. 我装的是ubuntu 13.10 64位,不一样的地方是,从casper文件夹复制出来的文件不是vmlinuz,而是vmlinuz.efi,相应的,menu.lst里也要将vmlin ...

  3. 套题T1

    间隙妖怪(gap.cpp/c/pas) 题目描述: 八云紫是幻想乡的间隙妖怪.她喜欢和八云橙玩一个叫做翻转的游戏.具体规则如下,八云紫对一个长度为N字符串做M次翻转操作,每次操作给定一个X,八云紫将X ...

  4. P1011 传纸条//dp优化改进状态表示

    P1011 传纸条 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2008复赛提高组第三题 描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不 ...

  5. Pascal编译器大全(非常难得)

    http://www.pascaland.org/pascall.htm Some titles (french) : Compilateurs Pascal avec sources = compi ...

  6. java:定义线程

    Thread是java.lang包的类,默认导入. 进程:操作系统中的程序,多进程即同时运行多个程序.线程:程序中的流,多线程即程序中有多个流同时执行. 一个线程用一个线程对象表示 创建线程的方法: ...

  7. 编写自己的TRACE函数

    TRACE函数是MFC里面的一个宏,是对OutputDebugString的封装. OutputDebugString的作用是输出调试信息,不要以为这个函数只有在Debug版本才会打日志,即使是Rel ...

  8. alias 命令

    功能说明:设置指令的别名. 语 法:alias[别名]=[指令名称] 参 数 :若不加任何参数,则列出目前所有的别名设置. 举    例 :ermao@lost-desktop:~$ alias    ...

  9. spring+hibernate+Struts2 整合(全注解及注意事项)

    最近帮同学做毕设,一个物流管理系统,一个点餐系统,用注解开发起来还是很快的,就是刚开始搭环境费了点事,今天把物流管理系统的一部分跟环境都贴出来,有什么不足的,请大神不吝赐教. 1.结构如下 2.jar ...

  10. 面向对象设计Object Oriented Design

    http://www.codeproject.com/Articles/93369/How-I-explained-OOD-to-my-wife http://www.cnblogs.com/niyw ...